Created
April 22, 2025 14:42
-
-
Save fabianbaechli/55a46ad3ea75678dbc3c4f89c169e313 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct node* BSTTreeInsert(struct node* p, struct node* r) { | |
struct node* y = NULL; | |
struct node* x = r; | |
while (x != NULL) { | |
// y is one step behind y = x; | |
if (x -> key < p -> key) { | |
x = x -> rgt; | |
} else { | |
x = x -> lft; | |
} | |
} | |
// Three cases | |
if (y == NULL) r = p; | |
else if (y->key < p->key) y->rgt = p; | |
else y->lft = p; | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment