示例#1
0
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;
}
示例#2
0
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);
}
示例#3
0
文件: main.c 项目: beingzeroin/cps-9
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;
}
示例#4
0
void putMap(Map map, string key, void *value) {
   BSTNode node;

   node = insertBSTNode(map->bst, key);
   setNodeValue(node, value);
}