// hasNext, next, remove are common iterator methods public NeighborIterator(DoubleEndedLinkedList theNeighbors) { this.theNeighbors = theNeighbors; currentNeighbor = theNeighbors.firstLink; previousNeighbor = theNeighbors.lastLink; }
public static void Main(string[] args) { DoubleEndedLinkedList theLinkedList = new DoubleEndedLinkedList(); theLinkedList.insertInFirstPosition("Mark Evans", 7); theLinkedList.insertInFirstPosition("Piers Polkiss", 9); theLinkedList.insertInFirstPosition("Doreen Figg", 6); theLinkedList.insertInLastPosition("Petunia Dursley", 4); /* * theLinkedList.insertInOrder("Mark Evans", 7); * theLinkedList.insertInOrder("Piers Polkiss", 9); * theLinkedList.insertInOrder("Doreen Figg", 6); * theLinkedList.insertInOrder("Petunia Dursley", 4); */ theLinkedList.display(); theLinkedList.insertAfterKey("Derek Banas", 2, 6); theLinkedList.display(); Console.WriteLine("\n"); // Send the LinkedList to the iterator NeighborIterator neighbors = new NeighborIterator(theLinkedList); // Get the first neighbor and display neighbors.currentNeighbor.display(); // Is there another? Console.WriteLine(neighbors.hasNext()); // Switch to the next Neighbor neighbors.next(); neighbors.currentNeighbor.display(); neighbors.remove(); neighbors.currentNeighbor.display(); Console.ReadLine(); }