7.2k views
4 votes
Help to how to write pseudo code to insert a new node to Binary Search Tree. Using C++.

1 Answer

6 votes

Answer:

Let the function be Node* ins(Node *root,int k)

if root node is NULL then return new node with data equal to k.

If the k <root->data

root->left=ins(root->left,k);

else if k >root->data

root->right =ins(root->right,k);

At last return root.

Step-by-step explanation:

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

User Sameer Kulkarni
by
5.9k points