Ejemplo n.º 1
0
 public void InsertNode(int value)
 {
     if (value >= Data)
     {
         if (RightNode == null)
         {
             RightNode = new Node(value);
         }
         else
         {
             RightNode.InsertNode(value);
         }
     }
     else
     {
         if (LeftNode == null)
         {
             LeftNode = new Node(value);
         }
         else
         {
             LeftNode.InsertNode(value);
         }
     }
 }
Ejemplo n.º 2
0
        //----------------INSERT NODE----------::START::-----------------------------------------------------------------------------------

        public void InsertNode(int InsertedData)
        {
            if (InsertedData < Data)
            {
                if (LeftNode == null)
                {
                    LeftNode = new BinaryNode(InsertedData);//Crates Node when it finds the correct place
                }
                else
                {
                    //Looping - Rekrusion
                    LeftNode.InsertNode(InsertedData);//Traverse through all nodes till it finds the last node and make the inserted node child
                    //Searching for the coorect place of the Node and when it finds it "Creates the Node - Its the If LeftNode = null"
                }
            }

            else if (InsertedData > Data)//If its bigger than the Data "RIGHT"
            {
                if (RightNode == null)
                {
                    RightNode = new BinaryNode(InsertedData);
                }
                else
                {
                    RightNode.InsertNode(InsertedData);
                }
            }
        }