hello everybody
I was just lookin at binary search tree some of the member functions like insert,remove, search etc. and i started thinking is there any way i can get nodecount,leafcount and tree height. Plz share some ideas about them.
akash
well, there is a standard tree traversal method which uses recursion. A node is made up of data and a left & right pointer to other nodes. The traversal looks something like
void traverse(node* n)
{
if(!n)
return;
traverse(n->left);
traverse(n->right);
}
now you could modify this to return a value. THe other step to count leaves would be
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.