public AlphabeticalOrderIterator(WordsCollection collection, bool reverse = false) { this._collection = collection; this._reverse = reverse; if (reverse) { _position = collection.getItems().Count; } }
public void ClientCode() { var collection = new WordsCollection(); collection.AddItem("First"); collection.AddItem("Second"); collection.AddItem("Third"); Console.WriteLine("Straight traversal:"); foreach (var element in collection) { Console.WriteLine(element); } Console.WriteLine("\nReverse traversal:"); collection.ReverseDirection(); foreach (var element in collection) { Console.WriteLine(element); } }