Given a binary search tree with the following declaration:
I need to find all the shortest paths in the tree. For example:Code:struct node
{int value;
Node *left, *right;};
class BST{
private:
Node *head;
public:
BST(){head = NuLL;}
};
I should print:
10
/ \
6 15
/ \ \
2 7 12
10 6 2
10 6 7
10 15 12
I am allowed to make use of data structures of list, stack and queue together with their basic manipulation functions.
Can someone give me an idea on how should i start(don't need codes)? I believe i need to find the min ht of the tree first, but i dont even know how to do that.
Second Question:
How is a function to find the max ht of a BST typically written? I thought of one way and i need someone to tell me if there's a better way
Code://pass the root of a non empty tree to this node
// the functions returns the max ht through maxHt
void BST::findMaxHt(node *rt,int curHt=0, int &maxHt)
{
if(rt==NULL) return;
if(curHt>maxHt)
maxHt= curHt;
findMaxHt(rt->left, curHt+1, maxHt);
findMaxtHt(rt->right, curHt+1, maxHt);
}