tree_data *rb_insert(rb_tree * tree, long int distance) { rb_node *n; tree_data *data; /* We search for the right place to insert */ data = rb_search(tree, distance); /* If the node doesn't exists */ if (!data) { /* we create the node */ n = new_rb_node(tree); (n->data).queue.first = NULL; (n->data).queue.last = NULL; /* then we rebalance the tree */ rb_insert_rebalancing(tree); return &(n->data); } return data; }
static rb_node_t * rbt_simple_insert(redBlackTree_t *T,int key) { int di; rb_node_t *node = raw_search_node(T,key,&di); if(di == RAW_SEARCH_EXIST) { fprintf(stderr,"key %d already exist!\n",key); return NIL_NODE; } rb_node_t *newNode = new_rb_node(key); if(newNode == NIL_NODE) { return NIL_NODE; } p(newNode) = node; if(di == RAW_SEARCH_LEFT_CHILD) { l(node) = newNode; }else if(di == RAW_SEARCH_RIGHT_CHILD) { r(node) = newNode; }else if(di == RAW_SEARCH_NULL_TREE) { T->root = newNode; } return newNode; }