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


C++ InternalNode::setLeftSibling方法代码示例

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


在下文中一共展示了InternalNode::setLeftSibling方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: split

InternalNode* InternalNode::split(int value){
  InternalNode* newNode = new InternalNode(internalSize, leafSize, parent, this, NULL);
  sort();
  BTreeNode* oldRightNode = getRightSibling();
  
  if(oldRightNode){
    oldRightNode->setLeftSibling(newNode);
    newNode->setRightSibling(oldRightNode);
    newNode->setLeftSibling(this);
  }
  
  //cout << keys[0] << " " << keys[1] << " " << keys[2] << endl;
  //cout << children[0]->getMinimum() << " " << children[1]->getMinimum() << endl;

  for(int i = ((internalSize+1) / 2); i < internalSize; i++){
    //cout << "Internal: Inserting " << keys[i] << " into new Node" << endl;
    newNode->insert(keys[i]);
  }

  count = count - newNode->getCount();
  
  if(keys[0] > value){
    newNode->insert(keys[0]);
    keys[0] = value;
  }

  else{
    newNode->insert(value);
  }
  
  setRightSibling(newNode);
  
  return newNode;
}
开发者ID:michaelromero,项目名称:Algorithms_DataStructures_CPP,代码行数:34,代码来源:InternalNode.cpp

示例2: insert

InternalNode* InternalNode::insert(int value)
{
  // students must write this
  updateMinimums();
  sort();
  //updateMinimums();
  //cout << "Starting InternalNode insert: " << value << endl;
  
  //search keys for position to insert, count - 1 because elements start at 0
  int searchKey = count-1;
  for(int i = count-1; keys[searchKey] > value && i > 0; i--){
    //cout << keys[searchKey] << " > " << value << endl;
    searchKey--;
  }
  BTreeNode* leafSplit = children[searchKey]->insert(value);
  updateMinimums();
  sort();
  //updateMinimums();
  //for(int i = 6; i >= 0; i--)
  //  cout << "Keys[" << i << "]: " << keys[i] << endl;
  if(!leafSplit){
    //cout << "no leaf split" << endl;
    return NULL;  
  }
  
  if(leafSplit && count < internalSize){
    //add here
    //cout << "InternalNode Insert Here" << endl;
    //cout << "InternalNode leafSplit has min: " << leafSplit->getMinimum() << endl;
    keys[count] = leafSplit->getMinimum();
    children[count] = leafSplit;
    count++;
    updateMinimums();
    sort();
    //updateMinimums();
    return NULL;
  }

  else if(leftSibling && leftSibling->getCount() < internalSize){
    //addToLeft(internalSplit)
    //cout << "NEED TO SHARE TO LEFT" << endl;
    //  cout << "Adding to left internal" << endl;
    ((InternalNode*)leftSibling)->insert(children[0]);
    ((InternalNode*)leftSibling)->updateMinimums();
    ((InternalNode*)leftSibling)->sort();
    //((InternalNode*)leftSibling)->updateMinimums();
    count--;
    for(int i = 0; i < count; i++)
    {
      children[i] = children[i + 1];
      keys[i] = keys[i + 1];
    }
      
      children[count] = leafSplit; 
      keys[count] = leafSplit->getMinimum();
      count++;
      updateMinimums();
      sort();
      //updateMinimums();
      //cout << "leafSplit min: " << leafSplit->getMinimum() << endl; 
      leafSplit->setParent(this);
      if(parent)
        parent->findMin(this);
      return NULL;
  }
  else if(rightSibling && rightSibling->getCount() < internalSize){
    //addtoRight
    if(keys[count-1] > leafSplit->getMinimum()){
      //cout << "Internal Passing to right: " << keys[count-1] << endl; 
      ((InternalNode*) rightSibling)->insert(children[count-1]);
      ((InternalNode*) rightSibling)->updateMinimums();
      ((InternalNode*) rightSibling)->sort();
      children[count-1] = leafSplit;
      updateMinimums();
      sort();
      if(((InternalNode*) rightSibling)->parent){
        (((InternalNode*) rightSibling)->parent)->updateMinimums();
        (((InternalNode*) rightSibling)->parent)->sort();

      }
    } 
    
    
    return NULL;
  }

  else if(leafSplit){
    //cout << "Internal Split" << endl;
    InternalNode* newRight = new InternalNode(internalSize, leafSize, parent, this, rightSibling);
    BTreeNode* oldRight = getRightSibling();
    if(rightSibling){
      oldRight->setLeftSibling(newRight);
      newRight->setRightSibling(oldRight);
      newRight->setLeftSibling(this);
    }
    
    rightSibling = newRight;
    int rightCount;
    for(int i = (internalSize+1) / 2; i < internalSize; i++){
      //cout << "i: " << i << endl;
//.........这里部分代码省略.........
开发者ID:michaelromero,项目名称:Algorithms_DataStructures_CPP,代码行数:101,代码来源:InternalNode.cpp


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