Question: Write a function to build a binary search tree from an array. The function will take in the array and the array size as arguments,

Write a function to build a binary search tree from an array. The function will take in the array and the array size as arguments, and return a pointer to the root of the tree.

Use the following function header:

Node *build(int a[], int size);

Use the following struct:

struct Node{

int key;

Node *parent;

Node *left;

Node *right;

Node(Node *p, Node *l, Node *r){

parent = p;

left = l;

right = r;

}

};

Use the following print statements as nodes are added to the tree:

If the node is placed as the parent node:

cout<<"root: "<key<<" parent: "<

If the node is placed as the left child:

cout<<"node: "<key<<" left child of: "<key<

If the node is placed as the right child:

cout<<"node: "<key<<" right child of: "<key<

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!