Esempio n. 1
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);
                }
            }
        }