20.5k views
0 votes
C++ write a simple pseudo code to insert a new node to Binary Search Tree.

User Valepu
by
5.8k points

1 Answer

3 votes

Answer:

  1. if root node is NULL then return new node with data equal mentioned.
  2. If the data <root->data
  3. root->left=recursive call on left subtree.
  4. else if data >root->data
  5. root->right =recursive call on right subtree.
  6. At last return root.

Step-by-step explanation:

Node is always inserted at the at the leaf node.We will search the data in the tree if we hit a the leaf node the new node is inserted as the child of the leaf node.

User Studgeek
by
4.9k points