Esempio n. 1
0
 public void removeFirst()
 {
     if (first == null)
     {
         return;
     }
     first = first.next;
     count--;
 }
Esempio n. 2
0
        public IEnumerator GetEnumerator()
        {
            OneListNode node = first;

            while (node != null)
            {
                yield return(node.val);

                node = node.next;
            }
        }
Esempio n. 3
0
        public void addFirst(int x)
        {
            if (first == null)
            {
                first = new OneListNode(x);
                return;
            }
            OneListNode node = new OneListNode(x);

            node.next = first;
            first     = node;
            count++;
        }
Esempio n. 4
0
        public int getIndex(int index)
        {
            if (index >= count)
            {
                return(0);
            }
            OneListNode node = first;

            while (index > 0)
            {
                node = node.next;
                index--;
            }
            return(node.val);
        }
Esempio n. 5
0
        public int getLast()
        {
            if (first == null)
            {
                return(0);
            }
            OneListNode temp   = first;
            OneListNode father = temp;

            while (temp != null)
            {
                father = temp;
                temp   = temp.next;
            }
            return(father.val);
        }
Esempio n. 6
0
        public void removeLast()
        {
            if (first == null)
            {
                return;
            }
            OneListNode temp   = first;
            OneListNode father = temp;

            while (temp != null)
            {
                father = temp;
                temp   = temp.next;
            }
            father = null;
            count--;
        }
Esempio n. 7
0
        public void addLast(int x)
        {
            if (first == null)
            {
                first = new OneListNode(x);
                return;
            }
            OneListNode temp   = first;
            OneListNode father = temp;

            while (temp != null)
            {
                father = temp;
                temp   = temp.next;
            }
            father.next = new OneListNode(x);
            count++;
        }
Esempio n. 8
0
        public void addIndex(int index, int x)
        {
            if (index >= count)
            {
                return;
            }
            OneListNode temp = first;

            while (index > 0)
            {
                temp = temp.next;
                index--;
            }
            OneListNode node = new OneListNode(x);

            node.next = temp.next;
            temp.next = node;
            count++;
        }
Esempio n. 9
0
        public OneListNode invert()
        {
            if (first == null)
            {
                return(null);
            }
            OneListNode node = first;
            OneListNode pre  = null;
            OneListNode next = null;

            while (node != null)
            {
                next      = node.next;
                node.next = pre;
                pre       = node;
                node      = next;
            }

            return(pre);
        }