コード例 #1
0
        ListNode ReverseNode(ListNode node)
        {
            HelperClasses.Display(node);
            ListNode current = node;
            ListNode prev    = null;

            while (current != null)
            {
                ListNode temp = current.next;

                current.next = prev;
                prev         = current;
                current      = temp;
            }
            HelperClasses.Display(prev);
            return(prev);
        }
コード例 #2
0
        public ListNode ReverseListFunction(ListNode head)
        {
            HelperClasses.Display(head);

            ListNode current = head;
            ListNode prev    = null;

            while (current != null)
            {
                ListNode nextTemp = current.next;
                current.next = prev;
                prev         = current;
                current      = nextTemp;
            }

            return(prev);
        }
コード例 #3
0
        public ReverseList()
        {
            ListNode head = new ListNode(1)
            {
                next = new ListNode(2)
                {
                    next = new ListNode(3)
                    {
                        next = new ListNode(4)
                        {
                            next = new ListNode(5)
                        }
                    }
                }
            };

            HelperClasses.Display(ReverseListFunction(head));
        }
コード例 #4
0
        public AddTwoNumbers()
        {
            ListNode l1 = new ListNode(2)
            {
                next = new ListNode(4)
                {
                    next = new ListNode(3)
                }
            };

            ListNode l2 = new ListNode(5)
            {
                next = new ListNode(6)
                {
                    next = new ListNode(4)
                }
            };

            HelperClasses.Display(AddTwoNumbersFunction(l1, l2));
        }