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


C++ BTreeNode::insertNonFull方法代码示例

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


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

示例1: insert

void BTree::insert(int k)
{

    if (root == NULL)
    {

        root = new BTreeNode(t, true);
        root->keys[0] = k;
        root->n = 1;
    }
    else
    {

        if (root->n == 2*t-1)
        {

            BTreeNode *s = new BTreeNode(t, false);
            s->C[0] = root;
            s->splitChild(0, root);
            int i = 0;
            if (s->keys[0] < k)
                i++;
            s->C[i]->insertNonFull(k);
            root = s;
        }
        else
            root->insertNonFull(k);
    }
}
开发者ID:bismoy2013,项目名称:Two-Roads-Algorithmic-Challenge,代码行数:29,代码来源:bokmarket.cpp

示例2: insert

// The main function that inserts a new key in this B-Tree
void BTree::insert(int k)
{
	char varnam[64];

	// If tree is empty
	if (root == NULL)
	{
		bzero(varnam, 64);
		sprintf(varnam,"%d",count);
		strcat(varnam,"node");
		varnam[64]=0;
		// Allocate memory for root
		root =(BTreeNode *)nvalloc_(sizeof(BTreeNode), varnam, 0);
		//root = (BTreeNode *)nvalloc_(sizeof(BTreeNode));
		root->Initialize(root, t, true, count);	
		//root = new BTreeNode(t, true);
		root->keys[0] = k; // Insert key
		root->n = 1; // Update number of keys in root
	}
	else // If tree is not empty
	{
		// If root is full, then tree grows in height
		if (root->n == 2*t-1)
		{
			bzero(varnam, 64);
			sprintf(varnam,"%d",count);
			strcat(varnam,"node");
			varnam[64]=0;

			// Allocate memory for root
			BTreeNode *s =(BTreeNode *)nvalloc_(sizeof(BTreeNode), varnam, 0);
			s->Initialize(s, t, false, count);	
			// Allocate memory for new root
			//BTreeNode *s = new BTreeNode(t, false);
			BEGIN_OBJTRANS((void *)s,0);

			// Make old root as child of new root
			s->C[0] = root;

			// Split the old root and move 1 key to the new root
			s->splitChild(0, root);

			// New root has two children now. Decide which of the
			// two children is going to have new key
			int i = 0;
			if (s->keys[0] < k)
				i++;
			s->C[i]->insertNonFull(k);

			nvcommitobj((void *)s,0);

			// Change root
			root = s;
		}
		else // If root is not full, call insertNonFull for root
			root->insertNonFull(k);
	}
	count++;
}
开发者ID:harveson,项目名称:nvmalloc,代码行数:60,代码来源:btree_new_wrd_trans.c

示例3: insert

void BTree::insert(int k)
{
    // If tree is empty
    if (root == NULL)
    {
        // Allocate memory for root
        root = new BTreeNode(t, true);
        root->keys[0] = k;  // Insert key
        root->n = 1;  // Update number of keys in root
    }
    else // If tree is not empty
    {
        // If root is full, then tree grows in height
        if (root->n == 2 * t - 1)
        {
            // Allocate memory for new root
            BTreeNode *s = new BTreeNode(t, false);

            // Make old root as child of new root
            s->C[0] = root;

            // Split the old root and move 1 key to the new root
            s->splitChild(0, root);

            // New root has two children now.  Decide which of the
            // two children is going to have new key
            int i = 0;
            if (s->keys[0] < k)
                i++;
            s->C[i]->insertNonFull(k);

            // Change root
            root = s;
        }
        else  // If root is not full, call insertNonFull for root
            root->insertNonFull(k);
    }
}
开发者ID:deepyadav442,项目名称:cosmos,代码行数:38,代码来源:b_tree.cpp


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