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


C++ BNode::setLeaf方法代码示例

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


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

示例1: splitInternal

void Btree::splitInternal(BNode* leaf, BNode* parent, pair<string,int> new_data) {
	// EVERYTHING UNTIL THE WHILE LOOP IS SPLITTING THE LEAVES AND CREATING NEW PARENTS

	pair<string,int> mid; // CONTAINS THE KEY VALUE WE ARE PUSHING UPWARDS
	BNode* np1; BNode* np2; // np1 = LEFT PARENT, np2 = RIGHT PARENT
	BNode* grandparent = parent->parent; // PARENT OF PARENT
	SpecialBNode* nodeHolder;

	BNode* n1 = new BNode(); // n1 = NEW LEAF NODE (TO THE RIGHT OF LEAF)
	nodeHolder = new SpecialBNode();
	int i = findIndex(parent, new_data);
	pair<string,int>* sorted_data = new pair<string,int>[5];
	for(int j=0; j < 4; j++) {
		nodeHolder->data[j] = parent->data[j];
	}
	nodeHolder->data[4] = leaf->data[2];
	sort(nodeHolder->data, 5);
	for(int j=0; j < 2; j++) {
		n1->data[j] = leaf->data[j+2];
		leaf->data[j+2].first = "~~~~~~~~~~~~";
		leaf->data[j+2].second = -10;
	}
	leaf->setLeaf(true);
	leaf->degree = 2; n1->degree = 2;
	n1->children[4] = leaf->children[4];
	leaf->children[4] = n1;
	mid = nodeHolder->data[2];
	for(int j=0; j<6; j++) {
		if(parent->children[j] != leaf)
			nodeHolder->children[j]=parent->children[j];
		else {
			nodeHolder->children[j]=leaf;
			nodeHolder->children[j+1]=n1;
			while(j<4) {
				nodeHolder->children[j+2]=parent->children[j+1];
				j++;
			}
			break;
		}
	}
	np1 = new BNode(); np2 = new BNode();
	np1->setLeaf(false); np2->setLeaf(false);
	np1->degree = 2; np2->degree = 2;
	for(int j = 0; j < 3; j++) {
		np1->children[j] = nodeHolder->children[j];
	 	nodeHolder->children[j]->parent = np1;
	 	np2->children[j] = nodeHolder->children[j+3];
	 	nodeHolder->children[j+3]->parent = np2;
	}
	for(int j=0; j < 2; j++) {
		np1->data[j] = nodeHolder->data[j];
		np2->data[j] = nodeHolder->data[j + 3];
	}
	while(grandparent != NULL && grandparent->degree == 4) { // KEEP PERCOLATING UP SPLITTING INTERNAL NODES
		nodeHolder = new SpecialBNode();
		for(int j=0; j < 4; j++) {
		 	nodeHolder->data[j] = grandparent->data[j];
		}
		nodeHolder->data[4] = mid;
		sort(nodeHolder->data, 5);
		mid = nodeHolder->data[2];
		for(int j=0; j<6; j++) {
			if(grandparent->children[j]!=parent)
				nodeHolder->children[j]=grandparent->children[j];
			else {
				nodeHolder->children[j]=np1;
				nodeHolder->children[j+1]=np2;
				while(j<4) {
					nodeHolder->children[j+2]=grandparent->children[j+1];
					j++;
				}
				break;
			}
		}
		np1=new BNode(); np2=new BNode();
		np1->setLeaf(false); np2->setLeaf(false);
		np1->degree=2; np2->degree=2;

		for(int j = 0; j < 3; j++) {
			np1->children[j] = nodeHolder->children[j];
		 	nodeHolder->children[j]->parent = np1;
		 	np2->children[j] = nodeHolder->children[j+3];
		 	nodeHolder->children[j+3]->parent = np2;
		}
		for(int j=0; j<2; j++) {
			np1->data[j] = nodeHolder->data[j];
			np2->data[j] = nodeHolder->data[j+3];
		}
		delete nodeHolder;
		nodeHolder = NULL;
		parent = grandparent;
		grandparent = grandparent->parent;
	}
	if(grandparent == NULL) { // WE NEED TO CREATE A NEW ROOT
		grandparent = new BNode();
		grandparent->setLeaf(false);
		grandparent->data[0] = mid;
		grandparent->degree++;
		grandparent->children[0] = np1;
		grandparent->children[1] = np2;
//.........这里部分代码省略.........
开发者ID:andychen152,项目名称:SocialNetwork,代码行数:101,代码来源:Btree.cpp


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