Exemple #1
0
        public Library(params Book[] books)
        {
            this.books = new List <Book>(books);
            BookComparator bookComparator = new BookComparator();

            this.books.Sort(bookComparator);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Book bookOne   = new Book("Animal Farm", 2003, "George Orwell");
            Book bookTwo   = new Book("The Documents in the Case", 2002, "Dorothy Sayers", "Robert Eustace");
            Book bookThree = new Book("The Documents in the Case", 1930);

            Library libraryOne = new Library();
            Library libraryTwo = new Library(bookOne, bookTwo, bookThree);

            foreach (var book in libraryTwo)
            {
                Console.WriteLine(book);
            }

            IComparer <Book> comparer = new BookComparator();
            //int min = 0;
            //for (int i = 0; i < libraryTwo.Books.Count; i++)
            //{
            //    for (int j = 0; j < libraryTwo.Books.Count; j++)
            //    {
            //        if (comparer.Compare(libraryTwo.Books[min], libraryTwo.Books[min])>0)
            //        {
            //            min = j;
            //        }


            //    }
            //    var temp = libraryTwo.Books[min];
            //    libraryTwo.Books[min] = libraryTwo.Books[i];
            //    libraryTwo.Books[i] = temp;

            //}

            //Console.WriteLine(libraryTwo.Books[min]);
        }
        public IEnumerator <Book> GetEnumerator()
        {
            var comparator = new BookComparator();

            books.Sort(comparator);
            for (int i = 0; i < books.Count; i++)    //that or the other commented lines!
            {                                        //that or the other commented lines!
                yield return(books[i]);              //that or the other commented lines!
            }                                        //that or the other commented lines!
            //return new LibraryIterator(this.books);
        }
Exemple #4
0
        public static void Main()
        {
            Book bookOne   = new Book("Animal Farm", 2003, "George Orwell");
            Book bookTwo   = new Book("The Documents in the Case", 2002, "Dorothy Sayers", "Robert Eustace");
            Book bookThree = new Book("The Documents in the Case", 1930);

            BookComparator bc = new BookComparator();

            Console.WriteLine((bc.Compare(bookOne, bookTwo) == -1));
            Console.WriteLine((bc.Compare(bookTwo, bookThree) == -1));
            Console.WriteLine((bc.Compare(bookThree, bookOne) == 1));
            Console.WriteLine((bc.Compare(bookOne, bookOne) == 0));
        }
Exemple #5
0
        public static void Main()
        {
            Book           bookOne   = new Book("Animal Farm", 2003, "George Orwell");
            Book           bookTwo   = new Book("The Documents in the Case", 2002, "Dorothy Sayers", "Robert Eustace");
            Book           bookThree = new Book("The Documents in the Case", 1930);
            BookComparator xFiles    = new BookComparator();

            Console.WriteLine(xFiles.Compare(bookTwo, bookThree));
            Library libraryOne = new Library();
            Library libraryTwo = new Library(bookOne, bookTwo, bookThree);

            foreach (var book in libraryTwo)
            {
                Console.WriteLine(book);
            }
        }
Exemple #6
0
        public Library(params Book[] books)
        {
            IComparer <Book> comparer = new BookComparator();

            this.books = new SortedSet <Book>(books, comparer);
        }