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

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

                node = node.next;
            }
        }
示例#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++;
        }
示例#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);
        }
示例#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);
        }
示例#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--;
        }
示例#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++;
        }
示例#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++;
        }
示例#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);
        }