Skip to content

Commit 4170c3a

Browse files
author
Raven G. Duran
committed
Added new menu item
1 parent 5b31b35 commit 4170c3a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

avl.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ void doInsert();
1717
void doDelete();
1818
void doSearch();
1919
void doInOrder();
20+
void doShowHeight();
2021

2122
// Functions for creating a BST structure
2223
struct node* newNode(int value,struct node *parent);
@@ -61,13 +62,15 @@ void showMenu(){
6162
printf("(2) Delete a Node\n");
6263
printf("(3) Search a Node\n");
6364
printf("(4) Print In Order\n");
64-
printf("(5) Exit\n");
65+
printf("(5) Show Heights of Root\n");
66+
printf("(6) Exit\n");
6567

6668
switch(getch()){
6769
case '1' : doInsert(); break;
6870
case '2' : doDelete(); break;
6971
case '3' : doSearch(); break;
7072
case '4' : doInOrder(); break;
73+
case '5' : doShowHeight(); break;
7174
default : exit(0);
7275
}
7376
}
@@ -203,6 +206,20 @@ void doInOrder(){
203206
showMenu();
204207
}
205208

209+
void doShowHeight(){
210+
system("cls");
211+
printf("--- Show Heights ---\n");
212+
if (tRoot!= NULL){
213+
printf("Node %d Height: %d\n",tRoot->value,getHeight(tRoot));
214+
printf("Node %d Left sub-tree Height: %d\n",tRoot->value,getHeight(tRoot->left));
215+
printf("Node %d Right subtree Height: %d\n",tRoot->value,getHeight(tRoot->right));
216+
} else printf("The tree is empty!\n");
217+
218+
printf("\n\n\nPress any key to continue...");
219+
getch();
220+
showMenu();
221+
}
222+
206223
struct node* newNode(int value,struct node *parent){
207224
struct node *root = (struct node*)malloc(sizeof(struct node));
208225
root->value = value;

avl.exe

544 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)