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


C++ InsertNode函数代码示例

本文整理汇总了C++中InsertNode函数的典型用法代码示例。如果您正苦于以下问题:C++ InsertNode函数的具体用法?C++ InsertNode怎么用?C++ InsertNode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: InsertNode

void InsertNode(int o,int left,int right,int pos,int val)
{
    if (left==right)
    {
        Tree[o].Max_Num=val;
        Tree[o].Occur_Num=1;
        return;
    }
    int mid=(left+right)/2;
    if (pos<=mid)
    {
        if (Tree[o].Left==0) Tree[o].Left=CreateNode();
        InsertNode(Tree[o].Left,left,mid,pos,val);
    } else
    {
        if (Tree[o].Right==0) Tree[o].Right=CreateNode();
        InsertNode(Tree[o].Right,mid+1,right,pos,val);
    }
    int Max_Left=-1,Max_Right=-1,Occur_Left=-1,Occur_Right=-1;
    if (Tree[o].Left>0)
    {
        Max_Left=Tree[Tree[o].Left].Max_Num;
        Occur_Left=Tree[Tree[o].Left].Occur_Num;
    }
    if (Tree[o].Right>0)
    {
        Max_Right=Tree[Tree[o].Right].Max_Num;
        Occur_Right=Tree[Tree[o].Right].Occur_Num;
    }
    if (Max_Left>Max_Right) {Tree[o].Max_Num=Max_Left;Tree[o].Occur_Num=Occur_Left;}
    if (Max_Left<Max_Right) {Tree[o].Max_Num=Max_Right;Tree[o].Occur_Num=Occur_Right;}
    if ((Max_Left==Max_Right)&&(Max_Right>0)) {Tree[o].Max_Num=Max_Left;Tree[o].Occur_Num=Occur_Left+Occur_Right;}
}
开发者ID:wcwswswws,项目名称:MyCode,代码行数:33,代码来源:ANUGCD.cpp

示例2: MakeNode

BstNode<KEY, VALUE>* AvlTree<KEY, VALUE>::InsertNode
(const KEY& insertkey, VALUE* insertvalue, int StoreAttrib_, BstNode<KEY, VALUE>* tree, int& confirm)
{
  if (tree == NULL)
  {
    confirm = 1;
    return MakeNode(insertkey, insertvalue, StoreAttrib_);
  }

  if (insertkey < tree->key)
    tree->left = InsertNode(insertkey, insertvalue, StoreAttrib_, tree->left, confirm);
  else if (insertkey > tree->key)
    tree->right = InsertNode(insertkey, insertvalue, StoreAttrib_, tree->right, confirm);
  else
  {
    confirm = 0;  
    StoreAttrib_ |= DataStorageAttributes::ACTIVE;
    tree->value.AssignPtr(insertvalue, StoreAttrib_);
    
    if (tree->value.Pointee() == NULL)
      cerr <<ERRMSG_NOMEMBST;
  }

  if (confirm)
    return Rebalance(tree);

  return tree;
}
开发者ID:heavilessrose,项目名称:my-sync,代码行数:28,代码来源:avltree.cpp

示例3: LFUListNode

/* put a new node in frequecy 1 queue, and update the hash table */
void LFUCache::PutNode(int frameid, int value) {
    LFUListNode* listnode = new LFUListNode(frameid, value);
    if(!Free)
        DeleteNode();
        
    /* case 1: if Head->next is the frequency 1 node*/
    if (FreqHead->Next && FreqHead->Next->Freq == 1) 
	InsertNode(listnode, FreqHead->Next);
		
    /* case 2: if Head is null || case 3: if Head->next is not the frequency 1 node*/
    else {
	FreqNode* nextfreq = new FreqNode(1);
	/* connect frequency node */
	if(FreqHead->Next) {
	    nextfreq->Next =  FreqHead->Next;
	    FreqHead->Next->Prev = nextfreq;
	}
	FreqHead->Next = nextfreq;
	nextfreq->Prev = FreqHead;
	InsertNode(listnode, nextfreq);
	cout<<listnode<<endl;
    }    
	
    /* insert to hash table */
    LFUHash.insert({frameid, listnode});
    Free--;
    return;
}
开发者ID:maolilan,项目名称:Cache,代码行数:29,代码来源:LFUcache.cpp

示例4: while

inline void SubAllocator::GlueFreeBlocks()
{
  RAR_MEM_BLK s0, * p, * p1;
  int i, k, sz;
  if (LoUnit != HiUnit)
    *LoUnit=0;
  for (i=0, s0.next=s0.prev=&s0;i < N_INDEXES;i++)
    while ( FreeList[i].next )
    {
      p=(RAR_MEM_BLK*)RemoveNode(i);
      p->insertAt(&s0);
      p->Stamp=0xFFFF;
      p->NU=Indx2Units[i];
    }
  for (p=s0.next;p != &s0;p=p->next)
    while ((p1=p+p->NU)->Stamp == 0xFFFF && int(p->NU)+p1->NU < 0x10000)
    {
      p1->remove();
      p->NU += p1->NU;
    }
  while ((p=s0.next) != &s0)
  {
    for (p->remove(), sz=p->NU;sz > 128;sz -= 128, p += 128)
      InsertNode(p,N_INDEXES-1);
    if (Indx2Units[i=Units2Indx[sz-1]] != sz)
    {
      k=sz-Indx2Units[--i];
      InsertNode(p+(sz-k),k-1);
    }
    InsertNode(p,i);
  }
}
开发者ID:alown,项目名称:iViewer,代码行数:32,代码来源:suballoc.cpp

示例5: GlueFreeBlocks

static inline void GlueFreeBlocks(PPMdSubAllocatorVariantH *self)
{
	if(self->LowUnit!=self->HighUnit) *self->LowUnit=0;

	self->sentinel.next=self->sentinel.prev=PointerToOffset(self,&self->sentinel);
	for(int i=0;i<N_INDEXES;i++)
	{
		while(self->FreeList[i].next)
		{
			struct PPMdMemoryBlockVariantH* p=(struct PPMdMemoryBlockVariantH *)RemoveNode(self,i);
			InsertBlockAfter(self,p,&self->sentinel);
			p->Stamp=0xFFFF;
			p->NU=self->Index2Units[i];
		}
	}

	for(struct PPMdMemoryBlockVariantH *p=OffsetToPointer(self,self->sentinel.next);
	p!=&self->sentinel;p=OffsetToPointer(self,p->next))
	{
		for(;;)
		{
			struct PPMdMemoryBlockVariantH *p1=p+p->NU;

			if(p1->Stamp!=0xFFFF) break;
			if(p->NU+p1->NU>=0x10000) break;

			RemoveBlock(self,p1);
			p->NU+=p1->NU;
		}
	}

	for(;;)
	{
		struct PPMdMemoryBlockVariantH *p=OffsetToPointer(self,self->sentinel.next);
		if(p==&self->sentinel) break;
		RemoveBlock(self,p);

		int sz=p->NU;
		while(sz>128)
		{
			InsertNode(self,p,N_INDEXES-1);
			sz-=128;
			p+=128;
		}

		int i=self->Units2Index[sz-1];
		if(self->Index2Units[i]!=sz)
		{
			i--;
			int k=sz-self->Index2Units[i];
			InsertNode(self,p+(sz-k),k-1);
		}
		InsertNode(self,p,i);
	}
}
开发者ID:1051215684,项目名称:theunarchiver,代码行数:55,代码来源:SubAllocatorVariantH.c

示例6: InsertNode

void InsertNode(BinaryTree *root, BinaryTree *node){
 	if(root->value < node->value){
   		if(root->rNode == NULL) root->rNode = node;
   		else InsertNode(root->rNode, node);
   		return ;
  	}else if(root->value > node->value){
  		if(root->lNode == NULL) root->lNode = node;
  		else InsertNode(root->lNode, node);
		return ;
  	}else return ;
}
开发者ID:clarkzhang56,项目名称:Search-method,代码行数:11,代码来源:binarytree.c

示例7: InsertNode

inline void SubAllocator::SplitBlock(void* pv,int OldIndx,int NewIndx)
{
  int i, UDiff=Indx2Units[OldIndx]-Indx2Units[NewIndx];
  byte* p=((byte*) pv)+U2B(Indx2Units[NewIndx]);
  if (Indx2Units[i=Units2Indx[UDiff-1]] != UDiff) 
  {
    InsertNode(p,--i);
    p += U2B(i=Indx2Units[i]);
    UDiff -= i;
  }
  InsertNode(p,Units2Indx[UDiff-1]);
}
开发者ID:alown,项目名称:iViewer,代码行数:12,代码来源:suballoc.cpp

示例8: main

// Ö÷º¯Êý
int main(void)
{
	int pos;

	printf("TEST 1...\n");
	LinkList *plist = CreateLinkList( );				// 创建单链表
	for(int pos = 0; pos < LIST_SIZE; pos++)			// 循环向单链表中插入数据
	{
		InsertNode(plist, pos, pos + 1);
	}
	ShowList(plist);									// 插入结束后显示单链表的信息

	DeleteNode(plist, 0);								// 删除第一个元素
	ShowList(plist);
	DeleteNode(plist, 1);								// 删除第二个元素
	ShowList(plist);

	ClearLinkList(plist);								// 将单链表清空
	ShowList(plist);
	DestroyLinkList(plist);								// 将单链表销毁
	plist = NULL;

	printf("\n\nTEST 2...\n");
	LinkList list;
	InitLinkList(&list);								// 初始化单链表
	for(int pos = 0; pos < LIST_SIZE; pos++)			// 训话向单链表中插入数据
	{
		InsertNode(&list, pos, pos + 1);
	}
	ShowList(&list);									// 显示单链表
	ClearLinkList(&list);								// 清空单链表
//	FinitLinkList(&list);		// ERROR== list->m_head->m_next == NULL
	ShowList(&list);

	printf("\n\nTEST 3...\n");
	LinkListNode *prevNode = &list;			// 带头结点的单链表头指针是list->m_next
	LinkListNode *addNode = NULL;
	for(int pos = 0; pos < LIST_SIZE; pos++)
	{
		if((addNode = AddNode(&list, prevNode, pos + 1)) != NULL)
		{
            prevNode = addNode;
		}
	}
	ShowList(&list);
	while(IsEmptyLinkList(&list) != true)			// 循环删除单链表中的数据
	{
		DeleteCurrNode(&list, list.m_next);
	}
	ShowList(&list);									// 显示单链表

	return 	EXIT_SUCCESS;
}
开发者ID:gatieme,项目名称:DataStructures,代码行数:54,代码来源:main.c

示例9: InsertNode

void InsertNode(node* n, int item, void* value)
{
    if(n== NULL)
    {
        n= malloc(sizeof(node));
        n->key = item;
    }
    else if(n->key > item)
    {
        if(n->left == NULL)
        {
			n->left= malloc(sizeof(node));
			n->left->key =item;
			n->left->value =value;
            n->left->parent= n;
            n->left->left=NULL;
            n->left->right=NULL;
			n->left->left_height = 0;
			n->left->right_height = 0;
			update_height(n->left);
			balance_tree(n->left);
        }
        else
        {
            InsertNode(n->left, item, value);
        }
    }
    else if(n->key < item)
    {
        if(n->right == NULL)
        {
			n->right= malloc(sizeof(node));
			n->right->key =item;
			n->right->value=value;
            n->right->parent= n;
            n->right->left=NULL;
            n->right->right=NULL;
			n->right->left_height = 0;
			n->right->right_height = 0;
			update_height(n->right);
			balance_tree(n->right);
        }
        else
        {
            InsertNode(n->right, item, value);
        }
    }
    else
    {
        printf("error item already in tree\n");
    }
}
开发者ID:jordanthomas761,项目名称:AVL-Tree,代码行数:52,代码来源:AVLTree.c

示例10: InsertNode

Tree InsertNode(Tree root, KEY_TYPE value)
{
    if (root == NULL) {
        return CreateTree(value);
    } else {
        if (value < root->key) {
            root->lchild = InsertNode(root->lchild, value);
        } else if (value > root->key) {
            root->rchild = InsertNode(root->rchild, value);
        }
        return root;
    }
}
开发者ID:Davidlx,项目名称:Learn-Algorithm,代码行数:13,代码来源:binary_search_tree.c

示例11: main

int main() 
{
	List list1, list2;
	list1 = CreateListPositive();
	list2 = CreateListNegative();	
	
	printf("Now insert an node into list1\n");
	List newNode1 = TryMalloc();
	newNode1->Num = 0;
	newNode1->Next = NULL;
	InsertNode(list1, newNode1, 0);

	List newNode2 = TryMalloc();
	newNode2->Num = 4;
	newNode2->Next = NULL;
	InsertNode(list1, newNode2, 4);
	
	PrintList(list1);


	
	printf("Append an element to the end of list2\n");
	List appendNode = TryMalloc();
	appendNode->Num = 88;
	appendNode->Next = NULL;
	AppendNode(list2, appendNode);

	PrintList(list2);



	printf("Now reverse list2...\n");
	List reversedList = ReverseMyList(list2);
	PrintList(reversedList);

	printf("Now switchs 3 and 4 in list2...\n");
	SwitchTwoNodes(reversedList, 3, 4);
	PrintList(reversedList);
	
	printf("Input \"y\" to destroy lists...");
	char c = getchar();
	getchar(); // Remove enter
	
	if(tolower(c) == 'y')
		{
			printf("Destrying the list...\n");
			DestroyList(list1);
			DestroyList(list2);
		}
}
开发者ID:WayneYe,项目名称:WayneDevLab,代码行数:50,代码来源:LinkedList.c

示例12: main

void main()
{
	cur *Cur = NULL;
	node *Node = NULL;
	InitList(&Node, &Cur);
	InsertNode(&Node, &Cur, 0, rand());
	InsertNode(&Node, &Cur, 1, rand());
	InsertNode(&Node, &Cur, 2, rand());
	DeleteNode(&Node, &Cur, 1);
	DeleteNode(&Node, &Cur, CountList(&Node, &Cur));
	DeleteNode(&Node, &Cur, 0);
 	ShowList(&Node, &Cur);
	ReleaseList(&Node, &Cur);
}
开发者ID:jianzhedeng,项目名称:DaHuaSJJG,代码行数:14,代码来源:test.c

示例13: SplitBlock

static void SplitBlock(PPMdSubAllocatorBrimstone *self,void *pv,int oldindex,int newindex)
{
	uint8_t *p=((uint8_t *)pv)+I2B(self,newindex);

	int diff=self->Index2Units[oldindex]-self->Index2Units[newindex];
	int i=self->Units2Index[diff-1];
	if(self->Index2Units[i]!=diff)
	{
		InsertNode(self,p,i-1);
		p+=I2B(self,i-1);
        diff-=self->Index2Units[i-1];
    }

    InsertNode(self,p,self->Units2Index[diff-1]);
}
开发者ID:AlexWMF,项目名称:Unarchiver,代码行数:15,代码来源:SubAllocatorBrimstone.c

示例14: count

treetype count(FILE *f,char name[],treetype root,treetype stopw)
{
  elementtype el;
  char s[255];
  char temp[81];
  char *part[30];
  int i;
  int line=0;
  if((f=fopen(name,"r"))==NULL)
    {printf("Can not open file %s.\n",name);
      exit(1);}
  while(fgets(s,255,f)!=NULL)
    {        
            line++;
            int size=parse(s,part);
            for(i=0;i<size;i++){
              el.count=1;if(i>0)strcpy(temp,part[i-1]);
              if(i>0&&temp[strlen(temp)-1]!='.'&&isupper(part[i][0])){}
              else{             
                          strcpy(el.name,part[i]);
                  
                        standardized(el.name);
                        strcpy(el.line,",");
                         char*tmp=itostr(line);
                         strcpy(&el.line[1],tmp);
                        if(strcmp(el.name,"\0")!=0&&(Search(el.name,stopw)==NULL))InsertNode(el,&root);
    }}}
  fclose(f);
        return root;
}
开发者ID:LVBK,项目名称:ThuchanhXDCTD,代码行数:30,代码来源:ex1.c

示例15: INodeNameA

void CSkeletonSetDlg::InsertNode(HTREEITEM parentItem , CMaxNodeTreeItem& Node)
{
    INode* pNode = Node.m_pMaxNode;

    int type = IMAGE_UNKNOWN;
    if(G_MaxEnv().IsBone(pNode) )
    {
        type = IMAGE_BONE;
    }
    if(G_MaxEnv().IsPureDummy(pNode))
    {
        type = IMAGE_DUMMY;
    }
    if(G_MaxEnv().IsMesh(pNode))
    {
        type = IMAGE_MESH;
    }

    Node.m_TreeItem = m_TreeNodes.InsertItem( INodeNameA(pNode),IMAGE_BONE,IMAGE_BONE,parentItem);
    m_TreeNodes.SetCheck(Node.m_TreeItem,TRUE);
    for(size_t i = 0 ; i < Node.m_ChildNodes.size(); i ++)
    {
        InsertNode(Node.m_TreeItem,Node.m_ChildNodes[i]);
    }
    m_TreeNodes.Expand(parentItem,TVE_EXPAND);
}
开发者ID:YOlodfssdf,项目名称:evolution3d,代码行数:26,代码来源:SkeletonSetDlg.cpp


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