本文整理汇总了C++中LeafNode::getRightSibling方法的典型用法代码示例。如果您正苦于以下问题:C++ LeafNode::getRightSibling方法的具体用法?C++ LeafNode::getRightSibling怎么用?C++ LeafNode::getRightSibling使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LeafNode
的用法示例。
在下文中一共展示了LeafNode::getRightSibling方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: remove
LeafNode* LeafNode::remove(int value)
{
int pos = 0;
// int q;
for(pos = 0; pos < count; pos++)
{
if(values[pos] == value)
{
for(int i = pos; i < count; i++)
{
values[i] = values[i + 1];
}
count--;
break;
}
if(values[pos] > value)
break;
}
if(count < ((leafSize+1)/2))
{
int transfer;
// BTreeNode *ptr2;
LeafNode *ptr;
int check = 0;
int siblingCount, i;
//int count1;
//Checks left sibling
// if(count == 0)
// return this;
if(leftSibling != NULL)
{
//cout << "left pass \n";
if((siblingCount = leftSibling->getCount()) > ((leafSize+1)/ 2))
{ //borrow from left
//cout << "problem left 1\n";
ptr = static_cast<LeafNode*>(leftSibling);
transfer = ptr->borrowLeft();
this->insert(transfer);
} else {//merge with left
//cout << "problem left 2 \n";
ptr = static_cast<LeafNode*>(leftSibling);
//cout << "ptr pass \n";
if(ptr->getLeftSibling() != NULL)
{
this->setLeftSibling(ptr->getLeftSibling());//Set new Sibling
leftSibling->setRightSibling(this);
} else {
this->setLeftSibling(NULL);
}
ptr->setRightSibling(NULL);
ptr->setLeftSibling(NULL);
for(i = 0; i < count; i++)
{
//cout << "seg1\n";
values[i + ptr->getCount()] = values[i];
}
for(i = ptr->getCount() - 1; i > -1; i--)
{
//cout << "seg2\n";
values[i] = ptr->values[i];
count++;
}
return ptr;
}
check = 1;
}//Left Sibling
if((check == 0) && (rightSibling != NULL))
{//borrow from right
if(rightSibling->getCount() > ((leafSize+1)/ 2))
{
ptr = static_cast<LeafNode*>(rightSibling);//borrow
transfer = ptr->borrowRight();
values[count] = transfer;
count++;
} else {
ptr = static_cast<LeafNode*>(rightSibling);//merge with right
if(ptr->getRightSibling() != NULL)
{
this->setRightSibling(ptr->getRightSibling());
rightSibling->setLeftSibling(this);
} else {
this->setRightSibling(NULL);
}
ptr->setLeftSibling(NULL);
ptr->setRightSibling(NULL);
for(i = 0; i < ptr->getCount(); i++)
//.........这里部分代码省略.........