"binary search tree c# stackoverflow" Code Answer's

You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "binary search tree c# stackoverflow" answered properly. Developers are finding an appropriate answer about binary search tree c# stackoverflow related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like binary search tree c# stackoverflow. Enter your desired code related query in the search bar and get every piece of information about C# code related question on binary search tree c# stackoverflow. 

binary search tree c# stackoverflow

By Expensive EchidnaExpensive Echidna on Sep 27, 2020
class Node
{
    public int data;
    public Node left, right;

    public Node(int data)
    {
        this.data = data;
        left = null;
        right = null;

    }
}

class BinaryTreeImp
{
    Node root;
    static int count = 0;

    public BinaryTreeImp()
    {
        root = null;

    }
    public Node addNode(int data)
    { 
        Node newNode = new Node(data);

        if (root == null)
        {
            root = newNode;

        }
        count++;
        return newNode;


    }

    public void insertNode(Node root,Node newNode )
    {
        Node temp;
        temp = root;

        if (newNode.data < temp.data)
            {
                if (temp.left == null)
                {
                    temp.left = newNode;

                }

                else
                {
                    temp = temp.left;
                    insertNode(temp,newNode);

                }
            }
            else if (newNode.data > temp.data)
            {
                if (temp.right == null)
                {
                    temp.right = newNode;

                }

                else 
                {
                    temp = temp.right;
                    insertNode(temp,newNode);
                }
            }
        }


    public void displayTree(Node root)
    {
        Node temp;
        temp = root;

        if (temp == null)
            return;
            displayTree(temp.left);
            System.Console.Write(temp.data + " ");
            displayTree(temp.right);


    }

    static void Main(string[] args)
    {
       BinaryTreeImp btObj = new BinaryTreeImp();
       Node iniRoot= btObj.addNode(5);


       btObj.insertNode(btObj.root,iniRoot);
       btObj.insertNode(btObj.root,btObj.addNode(6));
       btObj.insertNode(btObj.root,btObj.addNode(10));
       btObj.insertNode(btObj.root,btObj.addNode(2));
       btObj.insertNode(btObj.root,btObj.addNode(3));
       btObj.displayTree(btObj.root);

       System.Console.WriteLine("The sum of nodes are " + count);
       Console.ReadLine();

    }
}

Source: stackoverflow.com

Add Comment

0

All those coders who are working on the C# based application and are stuck on binary search tree c# stackoverflow can get a collection of related answers to their query. Programmers need to enter their query on binary search tree c# stackoverflow related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about binary search tree c# stackoverflow for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of binary search tree c# stackoverflow while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "binary search tree c# stackoverflow". Visit this developer's friendly online web community, CodeProZone, and get your queries like binary search tree c# stackoverflow resolved professionally and stay updated to the latest C# updates. 

C# answers related to "binary search tree c# stackoverflow"

View All C# queries

C# queries related to "binary search tree c# stackoverflow"

Browse Other Code Languages

CodeProZone