• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ InsertNode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ReadEllipseComplex

BOOL EllipseRecordHandler::ReadEllipseComplex(CXaraFileRecord *pCXaraFileRecord)
{
	BOOL ok = TRUE;

	NodeRegularShape *pEllipse;
	DocCoord CentrePoint;
	DocCoord MajorAxis;
	DocCoord MinorAxis;

	pEllipse = new NodeRegularShape;

	if (ok) ok = SetupShape(pEllipse);
	if (ok) ok = SetIsCircular(pEllipse, TRUE);

	if (ok) ok = pCXaraFileRecord->ReadCoord(&CentrePoint);
	if (ok) ok = SetCentrePoint(pEllipse, CentrePoint);

	if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&MajorAxis,0,0);
	if (ok) ok = SetMajorAxis(pEllipse, MajorAxis);

	if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&MinorAxis,0,0);
	if (ok) ok = SetMinorAxis(pEllipse, MinorAxis);

	if (ok) ok = InvalidateCache(pEllipse);
	if (ok) ok = InsertNode(pEllipse);

	return ok;
}
开发者ID:Amadiro,项目名称:xara-cairo,代码行数:28,代码来源:rechellp.cpp


示例17: ReadEllipseSimple

BOOL EllipseRecordHandler::ReadEllipseSimple(CXaraFileRecord *pCXaraFileRecord)
{
	BOOL ok = TRUE;

	NodeRegularShape * pEllipse;
	DocCoord CentrePoint;
	INT32 Height;
	INT32 Width;

	pEllipse = new NodeRegularShape;

	if (ok) ok = SetupShape(pEllipse);
	if (ok) ok = SetIsCircular(pEllipse, TRUE);

	if (ok) ok = pCXaraFileRecord->ReadCoord(&CentrePoint);
	if (ok) ok = SetCentrePoint(pEllipse, CentrePoint);

	if (ok) ok = pCXaraFileRecord->ReadINT32(&Width);
	if (ok) ok = pCXaraFileRecord->ReadINT32(&Height);
	if (ok) ok = SetHeightAndWidth(pEllipse, Height, Width);

	if (ok) ok = InvalidateCache(pEllipse);
	if (ok) ok = InsertNode(pEllipse);

	return ok;
}
开发者ID:Amadiro,项目名称:xara-cairo,代码行数:26,代码来源:rechellp.cpp


示例18: TheMinAndTheMax

void TheMinAndTheMax(IntNode *theList) {
	int a, min;
	int j = 0;
	int InMin = 0;
	int InMax = 0;
	int RemovedAtIndex = 0;
	a = CountList(theList);
	for (int j = 0; j < a; j++) {

		IntNode *TheMinNode = NodeAtIndex(theList, InMin);
		min = NodeAtIndex(theList, InMin)->value;

		for (int k = InMin; k < a; k++)
		{

			if (min >= TheMinNode->value)
			{
				min = TheMinNode->value;
				RemovedAtIndex = k;
			}

			TheMinNode = TheMinNode->nextNode;

		}

		InsertNode(theList, RemovedNode(theList, RemovedAtIndex), InMin);
		InMin++;

	}
	printf("Edited list\n\n");
	doPrintList(theList);
}
开发者ID:sergeyign,项目名称:2016,代码行数:32,代码来源:SingleList.c


示例19: FreqNode

/* update node to next frequency */
void LFUCache::UpdateNode(LFUListNode*& listnode) {
    	FreqNode* freqnode = listnode->FreqNodeQ; /* current frequency node */
        int frequency = freqnode->Freq; /* current frequency */
        
        /* if listnode is the only node in current frequency queue, PrevFreq
        is the previous frequency node, otherwise, is the current one. */
        FreqNode* nextfreq;

        /* case 1, the next FreqNode exists, and it is continuous */
        if (freqnode->Next && frequency + 1 == freqnode->Next->Freq) 
	    nextfreq = freqnode->Next;
	else {
            /* case 2, the next FreqNode is null */
	    /* case 3, the next FreqNode exists, and it is not continuous */
	    nextfreq = new FreqNode(frequency+1);
	    nextfreq->Next = listnode->FreqNodeQ->Next;
	    if(listnode->FreqNodeQ->Next)
	        listnode->FreqNodeQ->Next->Prev = nextfreq;
	}
	FreqNode* prevfreq = IsolateNode(listnode, nextfreq); 
	    
	/* connect the frequency node */
	 prevfreq->Next = nextfreq;
	 nextfreq->Prev = prevfreq;

	 /* insert the list node */
	 InsertNode(listnode, nextfreq);
	 return;
	
}
开发者ID:maolilan,项目名称:Cache,代码行数:31,代码来源:LFUcache.cpp


示例20: main

int
main() {
    listADT l = NewlistADT();
    string str1 = "hello";
    Position cp = l ;
    InsertNode(l, str1, cp);
    /*
    cp = cp -> next;
    string str2 = "world";
    InsertNode(l, str2, cp);
    cp = cp -> next;
    string str3 = "嘎嘎嘎上班其他";
    InsertNode(l, str3, cp);
    */

    cp = l -> next;
    while (cp != NULL) {
        cp = cp -> next;
    }
    /*
    FreeListADT(l);
    while (cp != NULL) {
    	printf("cp -> e: %s\n", (char *)cp -> e);
    	cp = cp -> next;
    }
    */

    char *s = "hello";
    Position p = Find(l, s, (cmpFnT)StringCmpFn);
    printf("p -> e: %s\n", (char *) (p -> e));

    return EXIT_SUCCESS;
}
开发者ID:wanglf,项目名称:ds,代码行数:33,代码来源:listADT.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Insist函数代码示例发布时间:2022-05-30
下一篇:
C++ InsertMenuItem函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap