Using recursion, insert a value into a tree: root = insert(node*, int) — bst_node* insert(bst_node* node, const int value) { if (node == 0) { bst_node* new_node = malloc(sizeof(bst_node)); if (new_node == NULL) { printf("Unable to allocate memory."); exit(0); } new_node->value = value; new_node->left = 0; new_node->right = 0; node = new_node; return node; } if (value < node->value) { node->left = insert(node->left, value); } else if (value > node->value) { node->right = insert(node->right, value); } return node; }
G
1.2K
Google Interview
This flashcard deck made by jwasham contains knowledge about google interview. For more details, please follow https://github.com/jwasham/google-interview-university