Skip to content

Instantly share code, notes, and snippets.

@Nolski
Created October 22, 2014 03:40
Show Gist options
  • Save Nolski/774b781cbb188973be81 to your computer and use it in GitHub Desktop.
Save Nolski/774b781cbb188973be81 to your computer and use it in GitHub Desktop.
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