本文整理汇总了C++中BTREE::compare方法的典型用法代码示例。如果您正苦于以下问题:C++ BTREE::compare方法的具体用法?C++ BTREE::compare怎么用?C++ BTREE::compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BTREE
的用法示例。
在下文中一共展示了BTREE::compare方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
void *BT_lookup(void *bti,void *data,int store)
{
/*
Lookup an entry in the tree. If store != 0, then store the
entry if it is not found. Otherwise return NULL if it is not
found. If found, the data pointer is returned.
I suppose there is no way to tell the difference between an entry
that is not found and one that is found but has NULL data pointer,
but I'm not going to worry about that today....
*/
BTREE *bt = (BTREE *) bti;
NODE *node = bt->head;
NODE *stack[STACK_SIZE];
int comp, top = 0;
/*
Special case -- first entry added to the tree
*/
if(node == NULL) {
if(store) {
bt->head = new_node(bt,data);
bt->n = 1;
}
return NULL;
}
/*
Go down tree looking for the data
*/
while(1) {
comp = bt->compare(data,node->data);
if(comp == 0) return node->data;
stack[top++] = node;
if(comp < 0) {
if(node->left) {
node=node->left;
} else {
if(store) {
node->left = new_node(bt,data);
node->balance--;
bt->n++;
if(node->balance < 0) adjust(stack,top);
}
return NULL;
}
} else {
if(node->right) {
node=node->right;
} else {
if(store) {
node->right = new_node(bt,data);
node->balance++;
bt->n++;
if(node->balance > 0) adjust(stack,top);
}
return NULL;
}
}
}
}
示例2: BT_delete
void BT_delete(void *bti, void *data)
{
/*
Go down the tree looking for this member. If we find it,
remove it.
*/
BTREE *bt = (BTREE *) bti;
NODE *node = bt->head;
NODE *stack[STACK_SIZE];
int comp,top=0;
while(1) {
comp = bt->compare(data,node->data);
if(comp < 0) {
if(node->left) {
stack[top++] = node;
node=node->left;
} else {
return; /* not found */
}
} else if(comp > 0) {
if(node->right) {
stack[top++] = node;
node=node->right;
} else {
return; /* not found */
}
} else {
/*
Found it.
*/
if(node->left) {
leftreplace(bt,node,stack,&top);
} else if(node->right) {
rightreplace(bt,node,stack,&top);
} else {
node->right = bt->unused;
bt->unused = node;
if(top) {
if(stack[--top]->left == node) {
stack[top]->left = NULL;
stack[top]->balance++;
if(stack[top]->balance != +1) shortened(stack,top+1);
} else {
stack[top]->right = NULL;
stack[top]->balance--;
if(stack[top]->balance != -1) shortened(stack,top+1);
}
} else {
bt->head = NULL;
}
}
bt->n--;
return;
}
}
}