Created
February 7, 2020 18:51
-
-
Save osamaadam/e85af7c824616fe019e14dfa27e27ca9 to your computer and use it in GitHub Desktop.
This file contains 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
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