void bstPrint(BinaryTreeNode *root)
{	
	if(root == NULL)
		return;
	
	printf("%.2f\n", root->key);
	bstPrint(root->leftChild);
	bstPrint(root->rightChild);
	
}
Exemple #2
0
void stPrintBlocks(symtable *st, unsigned int n)
{
    int i = listSize(st->blockList) - 1;
    while (i >= 0 && n > 0)
    {
        block *b = (block *) listGet(st->blockList, i);
        fprintf(stdout, "Block %d: %.*s\n", i, stringGetLength(b->name),
                stringGetBuffer(b->name));
        bstPrint(b->symbols, bstPrintSymbol);
        i--;
        n--;
    }
}
void main()
{
	BinaryTreeNode* node;
	BinaryTreeNode* root = (BinaryTreeNode*) malloc(sizeof(BinaryTreeNode));
	root->key = 5.5;
	root->leftChild = NULL;
	root->rightChild = NULL;
	bstInsert(root, 7.7);
	bstInsert(root, 3.2);
	bstInsert(root, 4.0);
	
	node = bstFind(root, 3.2);
	if(node != NULL)
	       printf("The value %.2f was found.\n", node->key);
	else
	       printf("Value 3.2 was not found.\n");
	       
	/*node = bstMin(root);
	if(node != NULL)
	       printf("The minimum value is %f.\n", node->key);
	node = bstMax(root);
	if(node != NULL)
	       printf("The maximum value is %f.\n", node->key);
	root = bstDelete(root, 3.2);
	node = bstFind(root, 3.2);
	if(node != NULL)
	       printf("The value %f was found.\n", node->key);
	else
	       printf("Value 3.2 was not found.\n";
	// delete the root
	root = bstDelete(root, 7.7);
	printf("Height of binary search tree is %d.\n", bstHeight(root)); bstClear(root);
*/

	bstPrint(root);
	printf("Height of binary tree is %d.\n", bstHeight(root));
}