Esempio n. 1
0
        /// <summary>
        /// Entry point.
        /// </summary>
        /// <param name="args">
        /// Start arguments.
        /// </param>
        public static void Main(string[] args)
        {
            Tree <int> tree = new Tree <int>(new TypeComparer.IntComparerDescending());

            var rand = new Random();

            for (int i = 0; i < 15; i++)
            {
                tree.Add(rand.Next(0, 1000));
            }

            Book book1 = new Book("C#", "Rihter", 99M);
            Book book2 = new Book("C++", "Someone", 135M);
            Book book3 = new Book("Delphi", "Borland", 200M);
            Book book4 = new Book("Pascal", "School", 30M);

            Tree <Book> bookTree = new Tree <Book>(new TypeComparer.BookComparerByPriceDescending());

            Book[] arrayOfBooks = new Book[]
            {
                new Book("The Great Gatsby", "F. Scott Fitzgerald", 120M),
                new Book("Catch-22", "Joseph Heller", 67M),
                new Book("On the Road", "Jack Kerouac", 85M),
                new Book("To Kill A Mockingbird", "Harper Lee", 140M),
                new Book("The Lord Of The Rings", "J. R. R. Tolkien", 125M),
                new Book("Lolita", "Vladimir Nabokov", 10M),
                new Book("The Catcher in the Rye", "JD Salinger", 150M),
                new Book("Midnight’s Children", "Salman Rushdie", 97M),
            };
            foreach (var book in arrayOfBooks)
            {
                bookTree.Add(book);
            }

            Point point1 = new Point(19, 80);
            Point point2 = new Point(1000, 25);
            Point point3 = new Point(30, 58);
            Point point4 = new Point(100, 70);
            Point point5 = new Point(1, 2);

            Tree <Point> pointTree = new Tree <Point>(new TypeComparer.PointComparerVectorLength());

            pointTree.Add(point1);
            pointTree.Add(point2);
            pointTree.Add(point3);
            pointTree.Add(point4);
            pointTree.Add(point5);

            string[] arrayOfString = new string[]
            {
                "lease",
                "incentive",
                "plug",
                "repetition",
                "wriggle",
                "housing",
                "fair",
                "generation",
                "due",
                "wave",
            };
            Tree <string> stringTree = new Tree <string>();

            foreach (string s in arrayOfString)
            {
                stringTree.Add(s);
            }

            foreach (int x in tree.TraversePreOrder())
            {
                Console.Write(x + " ");
            }

            Console.WriteLine();

            foreach (var x in bookTree.TraversePreOrder())
            {
                Console.WriteLine(x + " ");
            }

            Console.WriteLine();

            foreach (var x in pointTree.TraversePreOrder())
            {
                Console.Write(x + " ");
            }

            Console.WriteLine();

            foreach (var x in stringTree.TraversePreOrder())
            {
                Console.WriteLine(x + " ");
            }

            Console.ReadKey();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Tree theTree = new Tree();

            theTree.Add(20);
            theTree.Add(25);
            theTree.Add(45);
            theTree.Add(15);
            theTree.Add(67);
            theTree.Add(43);
            theTree.Add(80);
            theTree.Add(33);
            theTree.Add(67);
            theTree.Add(99);
            theTree.Add(91);
            theTree.UserInputForSearch();
            Console.ReadLine();
        }
Esempio n. 3
0
        /// <summary>
        /// Main method.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // these are used to decide whether to see
            // parts of the assignment that were required
            // on the handout.
            bool   userChoice;
            string choice;

            Tree <string> bt = new Tree <string>();

            // I tried to use an array to store the characters and then
            // iterate through these. I feel like the list of tree elements
            // could be entered by the user in a line, like:
            //          a,b,s,d,f,e,g
            // and read from that array, but I couldn't get it to work in a
            // way that would make writing that code worth the effort.
            //Console.WriteLine("Enter a series of values to add to the tree,
            //separated by commas: ");

            bt.moveTo(Relative.Root);

            // This could be done differently, I think
            // examples that use Add to add to a tree
            bt.Add("A", Relative.Root);
            bt.Add("B", Relative.LeftChild);
            bt.Add("C", Relative.RightChild);

            bt.moveTo(Relative.LeftChild);
            bt.Add("D", Relative.LeftChild);
            bt.moveTo(Relative.LeftChild);

            bt.Add("F", Relative.RightChild);

            bt.moveTo(Relative.Root);
            bt.moveTo(Relative.RightChild);
            bt.Add("E", Relative.RightChild);
            bt.moveTo(Relative.RightChild);

            bt.Add("G", Relative.LeftChild);

            // let's go to the top of the tree and demonstrate
            // the other functions we wrote for the assignment!
            bt.moveTo(Relative.Root);

            Console.WriteLine("Demonstration of Size method: ");
            Console.WriteLine(bt.GetTreeSize(bt));

            Console.WriteLine("Preorder Traversal");
            bt.PreOrder(bt.Root);
            Console.WriteLine("\n");

            Console.WriteLine("Inorder Traversal");
            bt.InOrder(bt.Root);
            Console.WriteLine("\n");

            Console.WriteLine("Postorder Traversal");
            bt.PostOrder(bt.Root);
            Console.WriteLine("\n");
            bt.moveTo(Relative.Root);

            // I could not make this work!
            //Console.WriteLine("Demonstration of Add requirement. Please enter a key...\n");
            //string str = Console.ReadLine();
            //bt.Add(str, Relative.Root);

            Environment.Exit(0);
        }