public static void Test() { // The client code may or may not know about the Concrete Iterator // or Collection classes, depending on the level of indirection you // want to keep in your program. WordsCollection wordcollection = new WordsCollection(); wordcollection.AddItem("First"); wordcollection.AddItem("Second"); wordcollection.AddItem("Third"); wordcollection.AddItem("4"); wordcollection.AddItem("5"); wordcollection.AddItem("6"); Console.WriteLine("--Straight traversal--"); foreach (var element in wordcollection) { Console.WriteLine(element); } Console.WriteLine("\n--Reverse traversal--"); wordcollection.ReverseDirection(); foreach (var element in wordcollection) { Console.WriteLine(element); } }
public AlphabeticalOrderIterator(WordsCollection _wordscollection, bool reverse = false) { this.wordscollection = _wordscollection; this.IsReverse = reverse; if (reverse) { this.position = _wordscollection.getItems().Count; } }