Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            BinaryTree bt       = new BinaryTree();
            Node       rootNode = new Node("Root");

            string[] values = new string[] { "Node", "Node", "45", "17", "10", "Node", "12", "0", null, "12.5" };

            foreach (string val in values)
            {
                bt.Add(rootNode, new Node(val));
            }

            Console.WriteLine("--Before FizzBuzz--");
            bt.BreadthFirst(rootNode);
            Console.WriteLine();


            Console.WriteLine("--After FizzBuzz--");
            bt.FizzBuzzTree(rootNode);
            bt.BreadthFirst(rootNode);

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Node n1 = new Node("10");
            Node n2 = new Node("15");
            Node n3 = new Node("3");
            Node n4 = new Node("17");

            BinaryTree binaryTree = new BinaryTree(n1);

            binaryTree.Add(n1, n2);
            binaryTree.Add(n1, n3);
            binaryTree.Add(n1, n4);
            Node random = FizzBuzzTree(n1);

            binaryTree.BreadthFirst(random);
        }
        static void Main(string[] args)
        {
            BinaryTree <object> tree = new BinaryTree <object>(1);

            tree.Root.LeftChild            = new Node <object>(2);
            tree.Root.LeftChild.LeftChild  = new Node <object>(4);
            tree.Root.LeftChild.RightChild = new Node <object>(15);

            tree.Root.RightChild            = new Node <object>(3);
            tree.Root.RightChild.LeftChild  = new Node <object>(6);
            tree.Root.RightChild.RightChild = new Node <object>(5);

            Console.WriteLine(String.Join(", ", tree.BreadthFirst(tree.Root)));

            BinaryTree <object> fizzBuzzTree = FizzBuzzTree(tree);

            Console.WriteLine(String.Join(", ", fizzBuzzTree.BreadthFirst(fizzBuzzTree.Root)));
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            // Declare placeholder variables - used later by various methods
            string menuSelection = "", newNodeInput = "";

            // Instantiate BinaryTree object, add initial values
            BinaryTree binTree = ResetBinaryTree();

            // Loop until the user enters the "8" key to exit the application
            do
            {
                // Prompt user to select an option from the menu
                PrintMainMenu();
                menuSelection = Console.ReadLine();
                Console.Clear();

                switch (menuSelection)
                {
                case "1":     // Adds a Node to the Binary Tree
                    Console.WriteLine("What value you like add to the Binary Tree?");
                    newNodeInput = Console.ReadLine();
                    Console.Clear();

                    string[] nodeInputArr = newNodeInput.Split(" ");

                    foreach (string n in nodeInputArr)
                    {
                        binTree.Add(binTree.Root, new Node(n));
                    }

                    Console.WriteLine("Success!");

                    PromptToReturnToMainMenu();
                    break;

                case "2":     // Converts Node Values to "FizzBuzz" values
                    Console.Write("Before: ");
                    binTree.PreOrder(binTree.Root);
                    Console.WriteLine();

                    binTree.ConvertToFizzBuzz(binTree.Root);

                    Console.Write("After: ");
                    binTree.PreOrder(binTree.Root);
                    Console.WriteLine();

                    PromptToReturnToMainMenu();
                    break;

                case "3":     // Resets Binary Tree to original Node Values
                    binTree = ResetBinaryTree();
                    Console.WriteLine("Your Binary Tree has been reset.");

                    PromptToReturnToMainMenu();
                    break;

                case "4":     // Prints the values in the Binary Tree in "Preorder" sequence
                    binTree.PreOrder(binTree.Root);

                    PromptToReturnToMainMenu();
                    break;

                case "5":     // Prints the values in the Binary Tree in "Postorder" sequence
                    binTree.PostOrder(binTree.Root);

                    PromptToReturnToMainMenu();
                    break;

                case "6":     // Prints the values in the Binary Tree in "Inorder" sequence
                    binTree.InOrder(binTree.Root);

                    PromptToReturnToMainMenu();
                    break;

                case "7":     // Prints the values in the Binary Tree in "Breadth First" sequence
                    binTree.BreadthFirst(binTree.Root);

                    PromptToReturnToMainMenu();
                    break;

                case "8":     // Exits the Program
                    Environment.Exit(0);
                    break;

                default:     // Handles cases where user doesn't enter a valid menu option
                    Console.WriteLine("That did not match one of the menu options. Try again.\n");
                    break;
                }
            } while (menuSelection != "8");
        }