For Implementation of BST:
<!--[if
!supportLists]-->Ø
<!--[endif]-->float avg(BinaryNode * rootNode)
int
BinarySearchTree::avg(BinaryNode * rootNode)
{
int avg=0,i=0;
Stack<BinaryNode* > stack;
BinaryNode* p;
p = root;
do
{
while( p != NULL )
{
stack.push( p );
p = p->left;
}
// at this point, left tree is empty
if( !stack.isEmpty()
)
{
p = stack.pop();
avg=avg+p->number;
p = p->right;
}
i++;
} while ( !stack.isEmpty() || p != NULL
);
return avg/i;
}
<!--[if
!supportLists]-->Ø
<!--[endif]-->int depth(BinaryNode * rootNode)
int
BinarySearchTree::depth(BinaryNode *rootNode) {
int leftHeight, rightHeight;
if (rootNode == NULL) {
return -1;
}
leftHeight = height(rootNode->left);
rightHeight = height(rootNode->right);
if (leftHeight >
rightHeight) {
return leftHeight+1;
} else {
return rightHeight+1;
}
}
// The depth/height of binary
tree
<!--[if
!supportLists]-->Ø
<!--[endif]-->bool completeTree(BinaryNode *
rootNode)
//Code to determine if a binary tree is strictly or
complete binary tree.
bool
BinarySearchTree::completeTree(BinaryNode * rootNode)
{
Stack<BinaryNode* > stack;
BinaryNode* p;
p = root;
bool balance;
do
{
while( p != NULL )
{
stack.push( p );
if(p->left!=NULL
&& p->right!=NULL || p->left==NULL &&
p->right==NULL)
balance = true;
else return
false;
p = p->left;
}
if( !stack.isEmpty() )
{
p = stack.pop();
p = p->right;
}
} while ( !stack.isEmpty() || p !=
NULL );
}