Exemplo n.º 1
0
int
uLongTreeNode::totalNodes ()
{
    int	count = 0;
    count = totalNodes ( count );
    return count;
};
Exemplo n.º 2
0
int main(){
int option,val;
struct node *ptr;
create_tree(tree);
//clrscr();
do{
printf("\n***************MAIN MENU**********************");
printf("\n 1.Insert Element");
printf("\n 2.Pre-order Traversal");
printf("\n 3.In-order Traversal");
printf("\n 4.Post-order Traversal");
printf("\n 5.Find the smallest element");
printf("\n 6.Find the largest element");
printf("\n 7.Delete an element");
printf("\n 8.Count the total number of nodes");
printf("\n 9.Count the total number of External nodes");
printf("\n 10.Count the total number of Internal nodes");
printf("\n 11.Determine the height of the tree");
printf("\n 12.Find the mirror image of the tree");
printf("\n 13.Delete the tree");
printf("\n 14.Exit");
printf("\n*************************************************");
printf("\n\n");
printf("Enter your option : ");
scanf("%d",&option);

switch(option)
{
case 1: printf("\n Enter the value of the nuw node : ");
	scanf("%d",&val);
	tree=insertElement(tree,val);
	break;

case 2: printf("\n The Elements of the tree are : \n");
	preorderTraversal(tree);
	break;

case 3: printf("\n The Elements of the tree are : \n");
	inorderTraversal(tree);
	break;

case 4: printf("\n The Elements of the tree are : \n");
	postorderTraversal(tree);
	break;

case 5: ptr=findSmallestElement(tree);
	printf("\n The smallest Element of the tree is : %d",ptr->data);
	break;

case 6: ptr=findLargestElement(tree);
	printf("\n The largest Element of the tree is : %d",ptr->data);
	break;

case 7: printf("\n Enter the Element to be deleted : ");
	scanf("%d",&val);
	tree=deleteElement(tree,val);
	break;

case 8: printf("\n Total Number of Nodes in the tree is = %d",totalNodes(tree));
	break;

case 9: printf("\n Total Number of External Nodes = %d",totalExternalNodes(tree));
	break;

case 10: printf("\n Total Number of Internal Nodes = %d",totalInternalNodes(tree));
	 break;

case 11: printf("\n The Height of Binary Tree is = %d",Height(tree));
	 break;

case 12: tree=mirrorImage(tree);
	 break;

case 13: tree=deleteTree(tree);
	 break;

case 14: printf("Exit\n");
     break;

default:
	system("cls");
	printf("Invalid Option\n");
	printf("Re-enter your Option\n\n");
	
	
}
}while(option!=14);
getch();
return 0;

}
Exemplo n.º 3
0
int totalNodes(struct node *tree){
if(tree==NULL)
return 0;
else
return(totalNodes(tree->left)+totalNodes(tree->right)+1);
}