Skip to content

Commit 2821d25

Browse files
author
Raven G. Duran
committed
Refactored correctParents() function and Initialized documentation
1 parent 2833a62 commit 2821d25

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

avl.c

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void rotateRL(struct node *root);
2727

2828
void balanceCheck(struct node *root);
2929
void bFactorInorder(struct node *root);
30+
void correctParents(struct node *a,struct node *b,struct node *c,struct node *f);
3031

3132
// Common Operations for BST structues
3233
struct node* searchNode(struct node *root, int value); // Return NULL if not found or Pointer to node if found
@@ -326,14 +327,8 @@ void rotateRL(struct node *root){
326327
}
327328

328329
// Correct Parents
329-
if (a->left != NULL) a->left->parent = a;
330-
if (a->right != NULL) a->right->parent = a;
331-
if (b->left != NULL) b->left->parent = b;
332-
if (b->right != NULL) b->right->parent = b;
333-
if (c->left != NULL) c->left->parent = c;
334-
if (c->right != NULL) c->right->parent = c;
335-
if (f != NULL) f->left->parent = f;
336-
if (f != NULL) f->right->parent = f;
330+
correctParents(a,b,c,f);
331+
337332
}
338333

339334
void rotateRR(struct node *root){
@@ -354,14 +349,7 @@ void rotateRR(struct node *root){
354349
}
355350

356351
// Correct Parents
357-
if (a->left != NULL) a->left->parent = a;
358-
if (a->right != NULL) a->right->parent = a;
359-
if (b->left != NULL) b->left->parent = b;
360-
if (b->right != NULL) b->right->parent = b;
361-
if (c->left != NULL) c->left->parent = c;
362-
if (c->right != NULL) c->right->parent = c;
363-
if (f != NULL) f->left->parent = f;
364-
if (f != NULL) f->right->parent = f;
352+
correctParents(a,b,c,f);
365353
}
366354

367355
void rotateLR(struct node *root){
@@ -384,14 +372,7 @@ void rotateLR(struct node *root){
384372
}
385373

386374
// Correct Parents
387-
if (a->left != NULL) a->left->parent = a;
388-
if (a->right != NULL) a->right->parent = a;
389-
if (b->left != NULL) b->left->parent = b;
390-
if (b->right != NULL) b->right->parent = b;
391-
if (c->left != NULL) c->left->parent = c;
392-
if (c->right != NULL) c->right->parent = c;
393-
if (f != NULL) f->left->parent = f;
394-
if (f != NULL) f->right->parent = f;
375+
correctParents(a,b,c,f);
395376
}
396377

397378
void rotateLL(struct node *root){
@@ -412,14 +393,17 @@ void rotateLL(struct node *root){
412393
}
413394

414395
// Correct Parents
396+
correctParents(a,b,c,f);
397+
}
398+
399+
void correctParents(struct node *a,struct node *b,struct node *c,struct node *f){
415400
if (a->left != NULL) a->left->parent = a;
416401
if (a->right != NULL) a->right->parent = a;
417402
if (b->left != NULL) b->left->parent = b;
418403
if (b->right != NULL) b->right->parent = b;
419404
if (c->left != NULL) c->left->parent = c;
420405
if (c->right != NULL) c->right->parent = c;
421-
if (f != NULL) f->left->parent = f;
422-
if (f != NULL) f->right->parent = f;
406+
if (f != NULL) f->left->parent = f;
407+
if (f != NULL) f->right->parent = f;
423408
}
424409

425-

avl.exe

-478 Bytes
Binary file not shown.

documentation.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Documentation
2+
========
3+
4+
This is the initial documentation. I'll update it from time to time if I found bugs or things that
5+
needs to be discussed.

0 commit comments

Comments
 (0)