当前位置: 首页>>代码示例>>C++>>正文


C++ LeafNode::borrowLeft方法代码示例

本文整理汇总了C++中LeafNode::borrowLeft方法的典型用法代码示例。如果您正苦于以下问题:C++ LeafNode::borrowLeft方法的具体用法?C++ LeafNode::borrowLeft怎么用?C++ LeafNode::borrowLeft使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LeafNode的用法示例。


在下文中一共展示了LeafNode::borrowLeft方法的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++)
//.........这里部分代码省略.........
开发者ID:isiphonyourgas,项目名称:ecs60-hw2,代码行数:101,代码来源:LeafNode.cpp


注:本文中的LeafNode::borrowLeft方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。