Esempio n. 1
0
BTreeNode* InternalNode::remove(int value) {  
	BTreeNode *leaf = NULL;

  for(int i = 0; i < count; i++) {
  	
  	if(i == 0 && value <= keys[i]) leaf = children[0];
  	if(i == count - 1 && value >= keys[i]) leaf = children[i];
  	if(value >= keys[i] && value < keys[i+1]) leaf = children[i];

		if(leaf != NULL) {
			leaf = leaf->remove(value);
				//keys[i]	= children[i]->getMinimum();

			for(int i = 0; i < count; i++) {
				if(children[i]->getCount() == 0) {
					
					for(; i < count - 1; i++) {
						children[i] = children[i + 1];
						keys[i] = keys[i + 1];
					}

					--count;
					break;
				}
			}
		}

	}

	this->tryBorrowing(); 
	this->prune();

	if(parent == NULL && this->count == 1) return this->children[0] ;
	else return this;
} // InternalNode::remove(int value)
Esempio n. 2
0
void BTree::remove(int k)
{
	if (!root)
	{
		cout << "The tree is empty\n";
		return;
	}

	// Call the remove function for root
	root->remove(k);

	// If the root node has 0 keys, make its first child as the new root
	// if it has a child, otherwise set root as NULL
	if (root->n==0)
	{
		BTreeNode *tmp = root;
		if (root->leaf)
			root = NULL;
		else
			root = root->C[0];

		// Free the old root
		delete tmp;
	}
	return;
}
void BTree::remove(string name) {
  //DELETE AT LEAF
  BTreeNode* leaf = findNode(root, name);
  if(leaf->find(name,EXACT)==NOTFOUND){
    cout << "TARGET NOT FOUND" << endl;
    return;
  }
  cout << "Found TARGET. Now deleting it. "<< endl;
  leaf=leaf->remove(name);
  cout << "DELETE SUCESSFULLY. Now ADJUSTING ROOT" <<endl;
  AdjustingRoot(leaf); 
}