NaryNode *insertBSTNode(NaryNode *root, NaryNode *newNode) { // Terminating condition if (root == NULL) return newNode; // Recurse into subtrees if (*(int*)(newNode->data) < *(int*)(root->data)) root->child[0] = insertBSTNode(root->child[0], newNode); else if (*(int*)(newNode->data) > *(int*)(root->data)) root->child[2] = insertBSTNode(root->child[2], newNode); else // if (*(int*)(newNode->data) == *(int*)(root->data)) root->child[1] = insertBSTNode(root->child[1], newNode); // Return the updated root node return root; }
void testBST() { int array[ARRAY_LEN]; randomize(array, ARRAY_LEN, ARRAY_MAX); int i; bstNode* head = NULL; for (i=0; i < ARRAY_LEN; i++) { insertBSTNode(&head, array[i]); } printInOrder(head); }
int main() { BSTNode *root = NULL; root = insertBSTNode(root, 5); root = insertBSTNode(root, 3); root = insertBSTNode(root, 1); root = insertBSTNode(root, 4); root = insertBSTNode(root, 7); root = insertBSTNode(root, 6); root = insertBSTNode(root, 9); print_ascii_tree(root); // Delete Root root = delteBSTNode(root, 5); print_ascii_tree(root); return 0; }
void putMap(Map map, string key, void *value) { BSTNode node; node = insertBSTNode(map->bst, key); setNodeValue(node, value); }