"searching display insert in a binary serach tree" 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 "searching display insert in a binary serach tree" answered properly. Developers are finding an appropriate answer about searching display insert in a binary serach tree related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like searching display insert in a binary serach tree. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on searching display insert in a binary serach tree. 

searching display insert in a binary serach tree

By ujjwal sotraujjwal sotra on May 21, 2021
#include <iostream>

using namespace std;
class node
{
public:
    int data;
    node*right;
    node*left;
};
node*getnewnode(int val)
{
    node *temp=new node;
    temp->data=val;
    temp->left=NULL;
    temp->right=NULL;
   return temp;
}
node*insertbst(node*root,int val)
{
    if(root==NULL)
    {
        return getnewnode(val);
    }
    if(root->data>val)
    {
        root->left= insertbst(root->left,val);
    }
    else
    {
        root->right= insertbst(root->right,val);
    }
    return root;
}
int searchbst(node*root,int val)
{
    if(root==NULL)
    {
        return 0;
    }
    if(root->data==val)
    {
        return 1;
    }
    if(root->data<val)
    {
        return searchbst(root->right,val);
    }
    else
    {
        return searchbst(root->left,val);
    }
}
void inorder(node*root)
{
    if(root==NULL)
    {
        return;
    }
    inorder(root->left);
    cout<<root->data<<" ";
    inorder(root->right);
}
int main()
{
    node*root=new node;
    root=NULL;
    while(1)
    {
        int value;
        cout<<"1.Insert to bst"<<endl<<"2.search in bst:"<<endl<<"3.display ordered bst"<<endl<<"4. exit"<<endl;
        int n;
        cout<<"enter your choice:"<<endl;
        cin>>n;
        switch(n)
        {
        case 1:
            {
                cout<<"enter the value to be inserted:"<<endl;
                cin>>value;
                root=insertbst(root,value);
                break;
            }
        case 2:
            {
                cout<<"enter the value you want to search:"<<endl;
                int search;
                cin>>search;
                int s=searchbst(root,search);
                if(s==1)
                {
                    cout<<"value found"<<endl;
                }
                else
                {
                    cout<<"value not found:"<<endl;
                }
                break;
            }
        case 3:
            {
                inorder(root);
                cout<<endl;
                break;
            }
        case 4:
            {
                exit(0);
            }
        default:
            {
                cout<<"invalid choice given:"<<endl;
            }

        }
    }
    return 0;
}

Add Comment

0

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

C++ answers related to "searching display insert in a binary serach tree"

View All C++ queries

C++ queries related to "searching display insert in a binary serach tree"

searching display insert in a binary serach tree function for searching in map in c++ hashtable linear probing ,insertion deletion searching binary search tree in cpp using class binary index tree c++ binary indexed tree binary tree search deletion in a binary search tree binary tree deletion top view of binary tree c++ heap sort heapify and max heap in binary tree binary search tree sorted order Write a program in C++ to find post-order predecessor of a node in a Binary Tree vertical traversal of binary tree Print Nodes in Top View of Binary Tree bst to insert tree c++ display numbers as binary linked list in c++ using class insert delete display in array gfg bottom view of tree gfg right view of tree gfg left view of tree tree in c++ stl gfg top view of tree dfenwick tree code c++ avl tree implementation c++ find the graph is minimal spanig tree or not diameter of tree using dfs centroid of a tree convert binary to decimal c++ stl how to do binary search in c++ using STL binary search program c++ binary exponentiation binary sort c++ binary addition using bitwise operators convert decimal to binary in c++ convert int to binary string c++ binary exponentiation modulo m binary search stl built in function in c++ for binary to decimal binary search function in c++ binary search in c++ write and read string binary file c++ convert long int to binary string c++ print binary in c how to do decimal to binary converdsion in c++ Decimal to binary c++ c++ binary search binary search algorithm binary heap decimal to binary predefined function find number of 1s in a binary cv::mat image c++ vector decimal to binary Print Decimal to binary using stack is obje file binary?? how to find the left most bit 1 in binary of any number c++ binary search lower bound how to show c++ binary files in sublime text binary algebra cpp building native binary with il2cpp unity C Binary Search binary search in java Binary Search implementation binary search in c binary search in stl Enter a key and display it's ascii value in c++ Write a program that inputs test scores of a student and display his grade Write a program to sort an array 100,200,20, 75,89.198, 345,56,34,35 using Bubble Sort. The program should be able to display total number of passes used for sorted data in given data set. how to display score using SDL in c++ Display a Text flowchart to display factors of a number insert vector to end of vector c++ insert at position in vector c++ insert function in c++ vector c++ vector insert time complexity map insert c++ c++ map insert Insert into vector C++ insert image using set atribute insert only unique values into vector c++ insert variable into string string insert c++ insert element in array c++ insert vector c++ cpp map insert insert into a vector more than once c++ insert priority queue c++ insert elements in array in c++11 c++ return value of set insert insert a value in pair in c++ qt insert image in widget vector insert

Browse Other Code Languages

CodeProZone