예제 #1
0
        private void SetList()
        {
            int[] _arr = new int[] { 1, 2, 5, 3, 9, 4 };

            _lc = CreateNode(_lc, _arr, 0);
            _lc.Print();
        }
예제 #2
0
 private void PrintNode(ListNode_lc node)
 {
     Console.WriteLine("{0}, ", node.val);
     if (node.next != null)
     {
         PrintNode(node.next);
     }
 }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }