Skip to content

Instantly share code, notes, and snippets.

@osamaadam
Created February 7, 2020 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osamaadam/e85af7c824616fe019e14dfa27e27ca9 to your computer and use it in GitHub Desktop.
Save osamaadam/e85af7c824616fe019e14dfa27e27ca9 to your computer and use it in GitHub Desktop.
void insert(Node *root, int data) {
if (root->right == NULL && data > root->data) {
Node *newNode = (Node *)malloc(sizeof(Node));
newNode->data = data;
root->right = newNode
} else if (root->left == NULL && data < root->data) {
Node *newNode = (Node *)malloc(sizeof(Node));
newNode->data = data;
root->left = newNode
} else if (data > root->data) {
insert(root->right, data);
} else {
insert(root->left, data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment