Using an iterative approach, insert a value into a BST: insert(node*, int) — void treeInsert(bst_node* node, int key) { bst_node* new_node; new_node = malloc(sizeof(*new_node)); assert(new_node); new_node->key = key; new_node->left = 0; new_node->right = 0; while (1) { if (node->key > key) { if (node->left) { node = node->left; } else { node->left = new_node; return; } } else { if (node->right) { node = node->right; } else { node->right = new_node; return; } } } }
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