Ejemplo n.º 1
0
        /// <summary>
        /// Adds a new integer to the list
        /// </summary>
        /// <param name="intVal">The value to add to the list</param>
        public void Add(int intVal)
        {
            IntNode node = new IntNode(intVal);

            // is this the first element in the list?
            if (head == null)
            {
                head = tail = node;
                count++;
                return;
            }

            tail.Next = node;
            tail      = node;
            count++;
        }
Ejemplo n.º 2
0
            public bool MoveNext()
            {
                if (currentNode == null)
                {
                    currentNode = head;
                    return(currentNode != null);
                }

                if (currentNode.HasNext)
                {
                    currentNode = currentNode.Next;
                    return(true);
                }

                return(false);
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the fifth last element in the list, using no more than one pass through the list
        /// </summary>
        /// <returns>fifth last element in the list</returns>
        public int GetFifthLast()
        {
            if (Count < 5)
            {
                throw new IndexOutOfRangeException("List must contain at least 5 elements");
            }

            if (count == 5)
            {
                return(head.Value);
            }

            IntNode current = head;

            for (int i = 0; i < (Count - 5); i++)
            {
                current = current.Next;
            }

            return(current.Value);
        }
Ejemplo n.º 4
0
 public void Dispose()
 {
     currentNode = null;
 }
Ejemplo n.º 5
0
 internal LinkedIntListEnumerator(IntNode headNode)
 {
     head = headNode;
 }
Ejemplo n.º 6
0
 public void Reset()
 {
     currentNode = null;
 }