Created
October 22, 2014 03:40
-
-
Save Nolski/774b781cbb188973be81 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
64 void insert(TreeNode* node, int val) { | |
65 if (node->left == NULL && node->right == NULL) { | |
66 | |
67 TreeNode n = { | |
68 val, | |
69 NULL, | |
70 NULL | |
71 }; | |
72 | |
73 if(val < node->data) { | |
74 node->left = &n; | |
75 } else if(val > node->data) { | |
76 node->right = &n; | |
77 } else { | |
78 return; | |
79 } | |
80 } else if (val < node->data) { | |
81 insert(node->left, val); | |
82 } else if (val > node->data) { | |
83 insert(node->right, val); | |
84 } | |
85 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment