Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BST leafcount()?

Status
Not open for further replies.

akashvij

Technical User
Mar 11, 2002
19
0
0
US
fellow plz give me some ideas how to get leafcount in binary search tree. i will be greatful.
 
You could keep track right from the beginning, and increment a leaf count each time you add on a new node to the binary tree. Or you can recursively transverse each node incrementing a count value to obtain the # of nodes. Mike L.G.
mlg400@linuxmail.org
 
will you plz expalin me in code i will be thank ful.
i have written so far is as follows


template<class T>
int BST<T>::getLeafCount(){
return getLeafCount(root);
}

template<class T>
int BST<T>::getLeafCount(BSTNode<T> *rt){
int count= 0;
if(rt==0){
return 0;
}else if(rt->left==0 && rt->right==0){

// need some code to get leafcount.

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top