Example #1
0
 public static void FizzBuzzTrees(BinaryTree tree)
 {
     TraverseTree(tree.Root);
 }
Example #2
0
 /// <summary>
 /// Create a method that takes in  a tree and passes the PreOrderFizzBuzz method to convert the value of the nodes.
 /// </summary>
 /// <param name="tree"></param>
 public static void FizzBuzzTree(BinaryTree tree)
 {
     PreOrderFizzBuzz(tree.root);
 }
Example #3
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");
        }
 public static void FizzBuzzTree(BinaryTree tree)
 {
     TraversePreOrder(tree.Root);
 }
 /// <summary>
 ///     Tree intake, mutation, and return
 /// </summary>
 /// <param name="tree">BinaryTree<object> tree</param>
 /// <returns>FizzBuzzTree</returns>
 public static BinaryTree <object> FizzBuzzTreeFunction(BinaryTree <object> tree)
 {
     FizzBuzzTreeWalk(tree.Root);
     return(tree);
 }