예제 #1
0
        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());
            }
        }
예제 #2
0
        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());
            }
        }