static void Main(string[] args) { ConcreteList a = new ConcreteList(); a[0] = "Item A"; a[1] = "Item B"; a[2] = "Item C"; a[3] = "Item D"; // Create Iterator and provide List BackwardIterator back = new BackwardIterator(a); object item = null; Console.WriteLine("Iterating over collection: with backward iterator"); item = back.First(); while (item != null) { Console.WriteLine(item); item = back.Next(); } Console.WriteLine(""); // Create Iterator and provide List ForwardIterator forward = new ForwardIterator(a); Console.WriteLine("Iterating over collection: with forward iterator"); item = forward.First(); while (item != null) { Console.WriteLine(item); item = forward.Next(); } // Wait for user Console.Read(); }
private void PatternStart() { Iterator iterator; List <int> _list = new List <int> (); _list.Add(2); _list.Add(3); _list.Add(5); IListCollection list = new ConcreteList(_list); iterator = list.GetIterator(); while (iterator.MoveNext()) { int i = (int)iterator.GetCurrent(); Log.Print(i.ToString()); iterator.Next(); } }
// Constructor public BackwardIterator(ConcreteList aggregate) { this.aggregate = aggregate; this.current = aggregate.Count - 1; }
// Constructor public ForwardIterator(ConcreteList aggregate) { this.aggregate = aggregate; }
public ConcreteIterator(ConcreteList list) { _list = list; _index = 0; }