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: "<
If the node is placed as the left child:
cout<<"node: "<
If the node is placed as the right child:
cout<<"node: "<
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
