Esempio n. 1
0
 public void Insert(int value)
 {
     if (value < Data)
     {
         if (LeftNode != null)
         {
             LeftNode.Insert(value);
         }
         else
         {
             LeftNode = new Node(value);
         }
     }
     else if (value > Data)
     {
         if (RightNode != null)
         {
             RightNode.Insert(value);
         }
         else
         {
             RightNode = new Node(value);
         }
     }
     else
     {
         Count++;
     }
 }
 public void Insert(int value)
 {
     if (value <= data)
     {
         if (left == null)
         {
             left = new Node(value);
         }
         else
         {
             left.Insert(value);
         }
     }
     else
     {
         if (right == null)
         {
             right = new Node(value);
         }
         else
         {
             right.Insert(value);
         }
     }
 }
Esempio n. 3
0
 //member methods
 public void Insert(int value)
 {
     if (value >= data)
     {
         if (rightChild == null)
         {
             rightChild = new Node(value);
         }
         else
         {
             rightChild.Insert(value);
         }
     }
     else
     {
         if (leftChild == null)
         {
             leftChild = new Node(value);
         }
         else
         {
             leftChild.Insert(value);
         }
     }
 }
Esempio n. 4
0
 //member methods
 public void Insert(int data)
 {
     if (root != null)
     {
         root.Insert(data);
     }
     else
     {
         root = new Node(data);
     }
 }
 public void Insert(int i)
 {
     if (root == null)
     {
         root = new Node(i);
     }
     else
     {
         root.Insert(i);
     }
 }
Esempio n. 6
0
        static void Main(string[] args)
        {
            Node boysNameTree = new Node();

            boysNameTree.Insert(5, "William");
            boysNameTree.Insert(1, "Noah");
            boysNameTree.Insert(10, "Benjamin");
            boysNameTree.Insert(8, "Alexander");
            boysNameTree.Insert(9, "Michael");
            boysNameTree.Insert(2, "Liam");
            boysNameTree.Insert(3, "Mason");
            boysNameTree.Insert(7, "James");
            boysNameTree.Insert(6, "Ethan");
            boysNameTree.Insert(4, "Jacob");
            Console.WriteLine(boysNameTree.Search("Noah"));
            Console.WriteLine(boysNameTree.Search("Liam"));
            Console.WriteLine(boysNameTree.Search("Ethan"));
            Console.WriteLine(boysNameTree.Search("Non-Existent Name"));
            Console.WriteLine(boysNameTree.Search("Kabrina"));
            boysNameTree.DFS();

            Node girlsNameTree = new Node();

            girlsNameTree.Insert(5, "Isabella");
            girlsNameTree.Insert(1, "Emma");
            girlsNameTree.Insert(10, "Harper");
            girlsNameTree.Insert(8, "Emily");
            girlsNameTree.Insert(9, "Charlotte");
            girlsNameTree.Insert(2, "Olivia");
            girlsNameTree.Insert(3, "Sophia");
            girlsNameTree.Insert(7, "Abigail");
            girlsNameTree.Insert(6, "Mia");
            girlsNameTree.Insert(4, "Ava");
            Console.WriteLine(girlsNameTree.Search("Ava"));
            Console.WriteLine(girlsNameTree.Search("Sophia"));
            Console.WriteLine(girlsNameTree.Search("Emma"));
            Console.WriteLine(girlsNameTree.Search("Non-Existent Name"));
            Console.WriteLine(girlsNameTree.Search("Kabrina"));
            girlsNameTree.DFS();
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            var rand = new Random();

            var rootNode = new Node(rand.Next(101));

            Console.WriteLine("Inserting 100 random integers into BST.");

            for (int i = 0; i < 100; ++i)
            {
                rootNode.Insert(rand.Next(101));
            }

            for (int i = 0; i < 5; ++i)
            {
                var key = rand.Next(101);
                SearchRecursively(key, rootNode);
                SearchEnumerating(key, rootNode);
            }
        }
Esempio n. 8
0
 public static void InitializeTree()
 {
     tree = new Node(50);
     tree.Insert(22);
     tree.Insert(33);
     tree.Insert(44);
     tree.Insert(99);
     tree.Insert(77);
     tree.Insert(88);
     tree.Insert(66);
     tree.Insert(55);
     tree.Insert(77);
     tree.Insert(10);
     tree.Insert(20);
     tree.Insert(80);
     tree.Insert(60);
     tree.Insert(90);
     tree.Insert(10);
     tree.Insert(67);
     tree.Insert(89);
     tree.Insert(18);
     tree.Insert(23);
     tree.Insert(82);
     tree.Insert(1);
     tree.Insert(100);
 }
Esempio n. 9
0
 public void Insert(int data)
 {
     rootNode.Insert(data);
 }