Answers for "Implement a C program to construct a Binary Search Tree, to search for an element in BST and to display the elements in the tree using Inorder traversal."

11

binary tree search

/* This is just the seaching function you need to write the required code.
	Thank you. */

void searchNode(Node *root, int data)
{
    if(root == NULL)
    {
        cout << "Tree is empty\n";
        return;
    }

    queue<Node*> q;
    q.push(root);

    while(!q.empty())
    {
        Node *temp = q.front();
        q.pop();

        if(temp->data == data)
        {
            cout << "Node found\n";
            return;
        }

        if(temp->left != NULL)
            q.push(temp->left);
        if(temp->right != NULL)
            q.push(temp->right);
    }

    cout << "Node not found\n";
}
Posted by: Guest on June-07-2020

Code answers related to "Implement a C program to construct a Binary Search Tree, to search for an element in BST and to display the elements in the tree using Inorder traversal."

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language