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); }
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); }
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)); }
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)); }