public static void Main(string[] args)
        {
            Node currentNode = null;

            Tree.Insert(ref currentNode, 10);
            Tree.Insert(ref currentNode, 20);
            Tree.Insert(ref currentNode, 15);
            Tree.Insert(ref currentNode, 0);
            Tree.Insert(ref currentNode, 5);

            Console.WriteLine("contains tests:");

            Console.WriteLine($"{Tree.Contains(currentNode, 10) == true} , 10 exists");
            Console.WriteLine($"{Tree.Contains(currentNode, 4) == false} , 4 does not exist");
            Console.WriteLine($"{Tree.Contains(currentNode, 20) == true} , 20 exists");
            Console.WriteLine($"{Tree.Contains(currentNode, 0) == true} , 0 exists");
            Console.WriteLine($"{Tree.Contains(currentNode, 100) == false} , 100 does not exist");

            Console.WriteLine("find min tests:");

            Console.WriteLine($"{Tree.FindMin(currentNode) == 0} , 0 is the minumim");

            Console.WriteLine("find max tests:");

            Console.WriteLine($"{Tree.FindMin(currentNode) == 20} , 20 is the maximum");

            Console.WriteLine("level-order traversal - can be used for printing the tree:");
            Tree.LevelOrder(currentNode);


            Console.WriteLine();
            Console.WriteLine("pre-order traversal");
            Tree.PreOrder(currentNode);


            Console.WriteLine();
            Console.WriteLine("in-order traversal - can be used for sorting the tree:");
            Tree.InOrder(currentNode);


            Console.WriteLine();
            Console.WriteLine("post-order traversal");
            Tree.PostOrder(currentNode);
        }
Exemple #2
0
        private void randomTreeBtn_Click(object sender, EventArgs e)
        {
            Tree <int> tree = new Tree <int>();

            Random rand  = new Random(DateTime.Now.Millisecond);
            string order = "";

            for (int i = 0; i < 5; i++)
            {
                int randInt = rand.Next(1, 500);
                tree.Insert(randInt);
                order += randInt + " ";
            }

            consoleTB.Text += "Root: " + tree.Root.Element + Environment.NewLine;
            consoleTB.Text += "Min element: " + tree.FindMin() + Environment.NewLine;
            consoleTB.Text += "Max element: " + tree.FindMax() + Environment.NewLine;
            consoleTB.Text += "Tree: " + tree;

            //string consoleText = consoleTB.Text;
        }