Skip to content

Commit 7bc042c

Browse files
author
Raven G. Duran
committed
Fixed some bugs and corrected some function names
1 parent c9a0069 commit 7bc042c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

avl.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,18 @@ void doDelete(){
107107
scanf("%d",&toDelete);
108108

109109
dNode = searchNode(tRoot,toDelete);
110-
110+
111111
if (dNode == NULL) printf("The node does not exist!\n");
112-
else {
113-
printf("The node is deleted!\n");
112+
else if(dNode == tRoot) {
113+
free(dNode);
114+
tRoot = NULL;
115+
dNode = NULL;
116+
printf("Node with value %d is deleted!\nThe tree is now empty.\n");
117+
printf("\n\n\nPress any key to continue...");
118+
getch();
119+
showMenu();
120+
} else {
121+
printf("Deleting node...\n");
114122
temp = dNode;
115123
if (dNode->left == NULL && dNode->right == NULL){ // Case 1 : leaf
116124
if (tRoot == dNode) tRoot = NULL;
@@ -146,6 +154,10 @@ void doDelete(){
146154
if (temp->parent != NULL) balanceCheck(temp->parent);
147155
temp = NULL;
148156

157+
printf("The node is now deleted!\n");
158+
159+
if(dNode != NULL) balanceCheck(dNode);
160+
149161
printf("\n--Balance Factor Sheet--\n");
150162
if (tRoot != NULL) bFactorPostOrder(tRoot);
151163
else printf("\nThe tree is empty!\n");
@@ -361,7 +373,7 @@ struct node* searchNode(struct node *root, int value){
361373
}
362374

363375
int getHeight(struct node *root){
364-
if (root==NULL)
376+
if (root==NULL || root == tRoot)
365377
return 0;
366378
else
367379
{

avl.exe

512 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)