/// <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++; }
public bool MoveNext() { if (currentNode == null) { currentNode = head; return(currentNode != null); } if (currentNode.HasNext) { currentNode = currentNode.Next; return(true); } return(false); }
/// <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); }
public void Dispose() { currentNode = null; }
internal LinkedIntListEnumerator(IntNode headNode) { head = headNode; }
public void Reset() { currentNode = null; }