Beispiel #1
0
        public static SingleListNode CreateSingleListedListByArray(int[] elements)
        {
            if (elements == null)
            {
                return(null);
            }

            SingleListNode ptr  = new SingleListNode(elements[0]);
            SingleListNode head = ptr;

            for (int i = 1; i < elements.Length; i++)
            {
                ptr.next = new SingleListNode(elements[i]);
                ptr      = ptr.next;
            }
            return(head);
        }
Beispiel #2
0
 public SingleListNode(int x)
 {
     val  = x;
     next = null;
 }