private void SetList() { int[] _arr = new int[] { 1, 2, 5, 3, 9, 4 }; _lc = CreateNode(_lc, _arr, 0); _lc.Print(); }
private void PrintNode(ListNode_lc node) { Console.WriteLine("{0}, ", node.val); if (node.next != null) { PrintNode(node.next); } }
private ListNode_lc CreateNode(ListNode_lc node, int[] arrVal, int k) { node = new ListNode_lc(arrVal[k]); if (k + 1 < arrVal.Length) { node.next = CreateNode(node.next, arrVal, k + 1); } return(node); }
private ListNode_lc DeleteNode(ListNode_lc list, int val) { ListNode_lc pointer = list; ListNode_lc prev = list; bool notDeleted = true; while (pointer != null && notDeleted) { if (pointer.val == val) { prev.next = pointer.next; notDeleted = false; } else { prev = pointer; pointer = pointer.next; } } return(list); }