static void Main(string[] args) { BookShelf bookShelf = new BookShelf(4); bookShelf.appendBook(new Book("Around the world in 80 days")); bookShelf.appendBook(new Book("Bible")); bookShelf.appendBook(new Book("Cinderella")); bookShelf.appendBook(new Book("Daddy-Long-Legs")); Iterator iterator = bookShelf.iterator(); Iterator invIterator = bookShelf.inverseIterator(); // 順方向にスキャンする while (iterator.hasNext()) { Book book = (Book)iterator.next(); Console.WriteLine(book.getName()); } // 逆方向にスキャンする while (invIterator.hasNext()) { Book book = (Book)invIterator.next(); Console.WriteLine(book.getName()); } }
public object Next() { Book book = BookShelf.GetBookAt(Index); this.Index++; return(book); }
static void Main(string[] args) { // max size 4の本棚を生成 BookShelf bookShelf = new BookShelf(4); bookShelf.AppendBook(new Book("CSharp Book")); bookShelf.AppendBook(new Book("VB Book")); bookShelf.AppendBook(new Book("Java Book")); bookShelf.AppendBook(new Book("Ruby Book")); //IEnumerator iterator = bookShelf.GetEnumerator(); Console.WriteLine("----------Loop BookShelf----------"); // IEnumerableインターフェースを実装しているとforeachが使える // foreach中ではiterator.MoveNext()とiterator.Currentの2つを自動で行ってくれる // ↓と同じことをしていることになる //var iterator = bookShelf.GetEnumerator(); //while (iterator.MoveNext()) //{ // Console.Write(iterator.Current); //} foreach (var book in bookShelf) { Console.WriteLine(book.Name); } Console.WriteLine(); Console.WriteLine("Iterator is initialized"); //iterator.Reset(); foreach (var book in bookShelf) { Console.WriteLine(book.Name); } Console.ReadLine(); }
static void Main(string[] args) { //拥有四本空书的书架 BookShelf bookShelf = new BookShelf(); //增加四本书进去 bookShelf.appendBook(new Book("Around the World in 80 Days")); bookShelf.appendBook(new Book("Blble")); bookShelf.appendBook(new Book("Cinderella")); bookShelf.appendBook(new Book("Daddy-Long-Legs")); bookShelf.appendBook(new Book("Daddy-Long-Legs")); bookShelf.appendBook(new Book("Daddy-Long-Legs")); bookShelf.appendBook(new Book("Daddy-Long-Legs")); bookShelf.appendBook(new Book("Daddy-Long-Legs")); bookShelf.appendBook(new Book("Daddy-Long-Legs")); bookShelf.appendBook(new Book("Daddy-Long-Legs")); bookShelf.appendBook(new Book("Daddy-Long-Legs")); Iiterator it = bookShelf.iterator(); while (it.hasNext()) { Book book = (Book)it.next(); Console.WriteLine(book.getName()); } }
static void Main(string[] args) { var bookShelf = new BookShelf(); bookShelf.AppendBook(new Book("書籍1")); Console.WriteLine(bookShelf.GetBookAt(0).Name); }
public bool HasNext() { if (Index < BookShelf.GetLength()) { return(true); } else { return(false); } }
static void Main(string[] args) { BookShelf bookShelf = new BookShelf(5); bookShelf.AddBook(new Book("자바 디자인 패턴")); bookShelf.AddBook(new Book("자바의 정석")); bookShelf.AddBook(new Book("jsp/servlet 3.0")); bookShelf.AddBook(new Book("데이터베이스")); Iterator it = bookShelf.iterator(); while (it.HasNext()) { Book books = (Book)it.Next(); Console.Write(books.GetName()); } }
static void Main(string[] args) { var bookShelf = new BookShelf(); bookShelf.AppendBook(new Book("Around the World in 80 Days")); bookShelf.AppendBook(new Book("Bible")); bookShelf.AppendBook(new Book("Cinderella")); bookShelf.AppendBook(new Book("Daddy-Long-Legs")); var iterator = bookShelf.Iterator(); while (iterator.HasNext()) { var book = (Book)iterator.Next(); Console.WriteLine(book.Name); } }
static void Main(string[] args) { BookShelf bookShelf = new BookShelf(); bookShelf.AppendBook(new Book("Around the world in 80 days")); bookShelf.AppendBook(new Book("Bigle")); bookShelf.AppendBook(new Book("Cinderella")); bookShelf.AppendBook(new Book("Daddy-Long-legs")); IIterator it = bookShelf.Iterator(); while (it.HasNext()) { Book book = (Book)it.Next(); Console.WriteLine(book.GetName()); } // 入力待ち Console.ReadLine(); }
static void Main(string[] args) { BookShelf bookShelf = new BookShelf(4); bookShelf.AppendBook(new Book("test1")); bookShelf.AppendBook(new Book("test2")); bookShelf.AppendBook(new Book("test3")); bookShelf.AppendBook(new Book("test4")); IIterator it = bookShelf.iterator(); while (it.hasNext()) { Book book = (Book)it.next(); Console.WriteLine(book.Name); } EndConsoleOut(); }
static void Main(string[] args) { BookShelf bookShelf = new BookShelf(4); bookShelf.AppendBook(new Book("Around the World in 80 Days")); bookShelf.AppendBook(new Book("Bible")); bookShelf.AppendBook(new Book("Cinderella")); bookShelf.AppendBook(new Book("Daddy-Long-Legs")); bookShelf.AppendBook(new Book("Manchi")); bookShelf.AppendBook(new Book("Reference Book")); IIterator it = bookShelf.Iterator(); while (it.HasNext()) { Book book = (Book)it.Next(); Console.WriteLine(book.GetName()); } // Console.WriteLine("Hello World!"); }
public BookShelfIterator(BookShelf bookShelf) { this.BookShelf = bookShelf; this.Index = 0; }
/// <summary> /// コンストラクタ /// </summary> /// <param name="bookShelf">本棚オブジェクト</param> public BookShelfInverseIterator(BookShelf bookShelf) { this.bookShelf = bookShelf; index = bookShelf.getLength() - 1; }
/// <summary> /// コンストラクタ /// </summary> /// <param name="bookShelf">スキャン対象の本棚オブジェクト</param> public BookShelfIterator(BookShelf bookShelf) { this.bookShelf = bookShelf; index = 0; }
public BookShelfIterator(BookShelf inBookShelf) { this.bookShelf = inBookShelf; this.index = 0; }
public BookShelfIterator(BookShelf bookShelf) { _bookShelf = bookShelf; _index = 0; }