コード例 #1
0
        public MyLinkNode RevertRecru()
        {
            MyLinkNode first = this;

            if (first.Next != null)
            {
                MyLinkNode leftNodeHead = first.Next.RevertRecru();

                first.Next = null;

                MyLinkNode temp = leftNodeHead;

                while (temp.Next != null)
                {
                    temp = temp.Next;
                }

                temp.Next = first;

                return(leftNodeHead);
            }
            else
            {
                return(first);
            }
        }
コード例 #2
0
        public void PrintNextAll()
        {
            MyLinkNode temp = this;

            while (temp != null)
            {
                Console.Write(temp.Data + "===>");
                temp = temp.Next;
            }

            Console.WriteLine();
        }
コード例 #3
0
        public MyLinkNode Revert()
        {
            MyLinkNode last    = this;
            MyLinkNode current = last.Next;

            last.Next = null;

            while (current != null)
            {
                MyLinkNode next = current.Next;

                current.Next = last;

                last = current;

                current = next;
            }

            return(last);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            MyLinkNode node1 = new MyLinkNode()
            {
                Data = 1
            };
            MyLinkNode node2 = new MyLinkNode()
            {
                Data = 2
            };
            MyLinkNode node3 = new MyLinkNode()
            {
                Data = 3
            };
            MyLinkNode node4 = new MyLinkNode()
            {
                Data = 4
            };
            MyLinkNode node5 = new MyLinkNode()
            {
                Data = 5
            };

            node1.Next = node2;
            node2.Next = node3;
            node3.Next = node4;
            node4.Next = node5;

            node1.PrintNextAll();

            MyLinkNode revertedNode = node1.Revert();

            revertedNode.PrintNextAll();

            revertedNode = revertedNode.RevertRecru();
            revertedNode.PrintNextAll();
        }