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


C++ DeQueue函数代码示例

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


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

示例1: BFSTraverse

/*-----------------------------------
    Breadth_First_Search
-----------------------------------*/
void BFSTraverse(MGraph G)
{
	int i, j;
	LinkQueue Q;

	for(i=0; i<G.numVertexs; i++)
		visited[i] = FALSE;
	InitQueue(&Q);
	for(i=0; i<G.numVertexs; i++)
	{
		if(visited[i] == TRUE)				//顶点是否已经被访问过
			continue;
		visited[i] = TRUE;
		printf("visited %c\n", G.vex[i]);	//访问顶点,或者进行其他操作
		EnQueue(&Q, i);						//该顶点序号入队列

		//当前队列不为空时,一直遍历
		while(QueueLength(Q)>0)
		{
			DeQueue(&Q,&i);					//出队列,得到出来的顶点的序号
			for(j=0; j<G.numVertexs; j++)
			{
				if((G.edge[i][j]!=0 || G.edge[i][j]!=INFINITY) && (visited[j]==FALSE))
				{
					printf("visited %c\n", G.vex[j]);
					visited[j] = TRUE;
					EnQueue(&Q, j);			//与i顶点相连的顶点j入队列
				}
			}
		}
	}

}
开发者ID:azengzz,项目名称:py_exercise_MyNote,代码行数:36,代码来源:MiniSpanTree_Prim.c

示例2: main

int main()
{
	int i;
	QElemType d;
	LinkQueue q;
	i=InitQueue(&q);
	if(i)
		printf("成功地构造了一个空队列!\n");
	printf("是否空队列?%d(1:空 0:否)  ",QueueEmpty(q));
	printf("队列的长度为%d\n",QueueLength(q));
	EnQueue(&q,-5);
	EnQueue(&q,5);
	EnQueue(&q,10);
	printf("插入3个元素(-5,5,10)后,队列的长度为%d\n",QueueLength(q));
	printf("是否空队列?%d(1:空 0:否)  ",QueueEmpty(q));
	printf("队列的元素依次为:");
	QueueTraverse(q);
	i=GetHead(q,&d);
	if(i==OK)
	 printf("队头元素是:%d\n",d);
	DeQueue(&q,&d);
	printf("删除了队头元素%d\n",d);
	i=GetHead(q,&d);
	if(i==OK)
		printf("新的队头元素是:%d\n",d);
	ClearQueue(&q);
	printf("清空队列后,q.front=%u q.rear=%u q.front->next=%u\n",q.front,q.rear,q.front->next);
	DestroyQueue(&q);
	printf("销毁队列后,q.front=%u q.rear=%u\n",q.front, q.rear);
	
	return 0;
}
开发者ID:Afaren,项目名称:reference,代码行数:32,代码来源:06链队列_LinkQueue.c

示例3: LevelOrderTraversal

void LevelOrderTraversal(struct TNode* root,int n){

if(!root){
return;
}

QNode* queue=CreateQueue(n);
EnQueue(queue,root);

struct TNode* tmpNode;

while(!IsEmptyQueue(queue)){

tmpNode=DeQueue(queue);
if(tmpNode){
printf("%d   ",tmpNode->data);
}
if(tmpNode->left){
EnQueue(queue,tmpNode->left);
}
if(tmpNode->right){
EnQueue(queue,tmpNode->right);
}

}




}
开发者ID:sidpka,项目名称:repo,代码行数:30,代码来源:BT_ClosestLeaf.C

示例4: Parent

TElemType Parent(CSTree T, TElemType cur_e)
{
	CSTree p, t;
	LinkQueue q;

	InitQueue(q);
	if (T) {
		if (Value(T) == cur_e)
			return Nil;
		EnQueue(q, T);
		while (!QueueEmpty(q)) {
			DeQueue(q, p);
			if (p->firstchild) {
				if (p->firstchild->data == cur_e)
					return Value(p);
				t = p;
				p = p->firstchild;
				EnQueue(q, p);
				while (p->nextsibling) {
					p = p->nextsibling;
					if (Value(p) == cur_e)
						return Value(t);
					EnQueue(q, p);
				}
			}
		}
	}
	return Nil;
}
开发者ID:zqw86713,项目名称:Data.Structure.Solution,代码行数:29,代码来源:bo6-5.cpp

示例5: BFSTraverse

/* 邻接矩阵的广度遍历算法 */
void BFSTraverse(MGraph G)
{
	int i, j;
	Queue Q;
	for(i = 0; i < G.numVertexes; i++)
       	visited[i] = FALSE;
    InitQueue(&Q);		/* 初始化一辅助用的队列 */
    for(i = 0; i < G.numVertexes; i++)  /* 对每一个顶点做循环 */
    {
		if (!visited[i])	/* 若是未访问过就处理 */
		{
			visited[i]=TRUE;		/* 设置当前顶点访问过 */
			printf("%c ", G.vexs[i]);/* 打印顶点,也可以其它操作 */
			EnQueue(&Q,i);		/* 将此顶点入队列 */
			while(!QueueEmpty(Q))	/* 若当前队列不为空 */
			{
				DeQueue(&Q,&i);	/* 将队对元素出队列,赋值给i */
				for(j=0;j<G.numVertexes;j++) 
				{ 
					/* 判断其它顶点若与当前顶点存在边且未访问过  */
					if(G.arc[i][j] == 1 && !visited[j]) 
					{ 
 						visited[j]=TRUE;			/* 将找到的此顶点标记为已访问 */
						printf("%c ", G.vexs[j]);	/* 打印顶点 */
						EnQueue(&Q,j);				/* 将找到的此顶点入队列  */
					} 
				} 
			}
		}
	}
}
开发者ID:CatcherX,项目名称:DataStructure,代码行数:32,代码来源:03邻接矩阵深度和广度遍历DFS_BFS.c

示例6: main

int main()
{
	LinkQueue Q;
	if(InitQueue(&Q))
	{
		QElemType e;

		printf("initialize successful");
		if(IsEmpty(Q))
		{
			printf("queue is IsEmpty\n");
		}

		for (int i=0;i<10;i++)
		{
			EnQueue(&Q,i);
		}

		GetHead(Q,&e);
		printf("The head element is %d\n",e );
		printf("The length of the queue is %d\n",GetLength(Q));

		DeQueue(&Q,&e);

		printf("delete element is %d\n",e);

		TraverseQueue(Q,*visit);
		if (DestroyQueue(&Q))
		{
			printf("DestroyQueue successful\n");
		}
	}
	return 0;
}
开发者ID:githubmsj1,项目名称:DataStructure,代码行数:34,代码来源:Queue.cpp

示例7: ASSERT

/**
Insert an unlocked page into the last position of the locked queue, may squeeze the original last page into
the unlocked queue.
This function is used on last visited but 'unlocked' pages to avoid excessive lock/unlock calls to cache memory
manager as contiguous entry reading/writing often happens on the same page.
@param  aPage   the page to be inserted.
@pre    the page type of aPage should only be TDynamicDirCachePage::EUnknown
*/
void CDynamicDirCache::MakePageLastLocked(TDynamicDirCachePage* aPage)
    {
    // this function should not be called on active pages
    ASSERT(aPage->iType == TDynamicDirCachePage::EUnknown);

    if (iLockedQ.IsEmpty())
        {
        // if locked queue is empty, add it onto the locked queue directly
        AddFirstOntoQueue(aPage, TDynamicDirCachePage::ELocked);
        }
    else
        {
        // otherwise, we squeeze for the last position on locked queue
        while (iLockedQCount + 1 >= iMinSizeInPages)
            {
            TDynamicDirCachePage* last = iLockedQ.Last();
            DeQueue(last);
            UnlockPage(last);
            AddFirstOntoQueue(last, TDynamicDirCachePage::EUnlocked);
            }

        // iLockedQCount + 1 < iMinSizeInPages
        iLockedQ.AddLast(*aPage);
        aPage->SetPageType(TDynamicDirCachePage::ELocked);
        iLockedQCount++;
        }
    }
开发者ID:kuailexs,项目名称:symbiandump-os1,代码行数:35,代码来源:sl_dir_cache.cpp

示例8: BFSTraverse

Status BFSTraverse(ALGrapth G, Status(visit)(VertexType), int num = 0){
	int i;
	visitfunc = visit;
	for(i = 0; i < G.vexnum; i++){
		visited[i] = FALSE;
	}
	LinkQueue Q;
	InitQueue(&Q);
	int j;
	for(i = num, j = 0; j < G.vexnum; i++, j++){
		if(i == G.vexnum) i = 0;
		if(!visited[i]){
			visited[i] = TRUE;
			visitfunc(G.vertices[i].data);
			EnQueue(&Q, i);
			int u;
			while(!isEmpty(Q)){
				DeQueue(&Q, &u);
				int w;
				for(w = FirstAdjVex(G, u); w >= 0; w = NextAdjVex(G, u, w)){
					// printf("w: %d\n", w);
					visited[w] = TRUE;
					visitfunc(G.vertices[w].data);
					EnQueue(&Q, w);
					// printf("step\n");
				}
				// printf("stop\n");
			}
		}
		// printf("end\n");
	}
}
开发者ID:qq3102328040,项目名称:playground-c,代码行数:32,代码来源:ALGraph.c

示例9: main

int main()
{
	LinkQueue lq;
	InitQueue(&lq);
	int input, count = 5;
	while(count)
	{
		scanf("%d", &input);
		EnQueue(&lq, input);
		count --;
	}
	count = 7;
	int deQueueOut;
	while(count)
	{
		if(DeQueue(&lq,&deQueueOut)){
			printf("I'm empty!\n");
			break;
		}else{
			printf("%d\n", deQueueOut);
		}
	}

	return 0;
}
开发者ID:ChinaLongGanHu,项目名称:Data-Structures-and-Algorithms,代码行数:25,代码来源:main.c

示例10: while

void *pthr_deal_cmd()
{
    while(p_n_over)
    {
        DEBUG_printf("next command!\n");
        if(1==SW)
        {
            DEBUG_printf("Web  Switch is OFF!\n");
            exit(1);
        }
        if(DeQueue(&Q_cmd,&deal_package_cmd))
        {
            DEBUG_printf("get a command head:%s!\n",deal_package_cmd.pkg_head);
            DEBUG_printf("get a command:%s!\n",deal_package_cmd.pkg_cmd);

            QueueTraverse(Q_cmd,visit);
            if(!deal_cmd(deal_package_cmd))
                continue;
            DEBUG_printf("after deal_cmd()\n");
            DEBUG_printf("get a command nonce:%s!\n",deal_package_cmd.pkg_nonce);

            NO_data=0;//data recived
            Insert(&deal_package_cmd,L_cmd,L_cmd);

            printf("new node:%s,%s==========\n",deal_package_cmd.pkg_cmd,deal_package_cmd.pkg_nonce);
            clear_recv(deal_package_cmd);
        }
        else
        {
            DEBUG_printf("queue empty1\n");
            sleep(1);
        }
    }
}
开发者ID:Spudz76,项目名称:Antminer_firmware,代码行数:34,代码来源:client.c

示例11: BFS

/*宽度优先*/ 
void BFS ( LGraph Graph, Vertex S)
{   
    Queue Q;     
    Vertex V;
    PtrToAdjVNode W; 
  
    InitializeQueue(&Q);
    /* 访问顶点S:此处可根据具体访问需要改写 */
    printf("% d",S);
    Printed[S] = true; /*本例中表示该节点已被输出*/
    Visited[S] = true; /* 标记S已访问 */
    EnQueue(S,&Q); /* S入队列 */
      
    while ( !QueueIsEmpty(&Q) ) {
        DeQueue(&V,&Q);  /* 弹出V */
        for( W=Graph->G[V].FirstEdge; W; W=W->Next ) /* 对图中的每个顶点W */
            if ( !Visited[W->AdjV] ) {
                /* 访问顶点W */
                printf("% d",W->AdjV);
                Printed[W->AdjV] = true; 
                Visited[W->AdjV] = true; 
                EnQueue(W,&Q); /* W入队列 */
            }
    }
}
开发者ID:LiZeC123,项目名称:C_and_CPP,代码行数:26,代码来源:邻接表表示法.c

示例12: isCompleteBiTree

/**
 * 习题4.49,非递归法判定给定二叉树是否为完全二叉树
 */
bool isCompleteBiTree(BiTree T)
{
	LinkQueue Q;
	InitQueue(Q);
	BiTree p;
	int flag = 1;	//是否遍历到达最后一层的标志,到达最后一层则flag置0
	p = T;
	while (p || !QueueEmpty(Q)) {
		if (p) {
			if (p->lchild && p->rchild && 1 == flag) {	//左右孩子都存在
				EnQueue(Q, p->lchild);
				EnQueue(Q, p->rchild);
			} else if (p->lchild && !p->rchild && 1 == flag) {	//左孩子存在,右孩子不存在,到达最后一层
				flag = 0;
				EnQueue(Q, p->lchild);
			} else if (!p->lchild && p->rchild)	//左孩子不存在,右孩子存在,结束
				return false;
			else if (!p->lchild && !p->rchild)	//左右孩子都不存在
				flag = 0;
			else
				return false;

			if (!QueueEmpty(Q))
				DeQueue(Q, p);
			else
				return true;
		}
	}
	return true;
}
开发者ID:Annie2333,项目名称:DS_Code,代码行数:33,代码来源:practice.cpp

示例13: BFSTraverse

Status BFSTraverse(MGraph G,Status(*Visit)(int v))
{
    Queue q;
    QElemType e;
    int i,j;

    for(i=0; i<G.vexnum; i++)
        Visited[i]=FALSE;

    if(!InitQueue(q))return ERROR;
    EnQueue(q,G.vexs[0]);//将第一个顶点入队
    Visited[0]=TRUE;

    printf("广度优先遍历:");
    while(!QueueEmpty(q))
    {
        GetHead(q,e);
        i=LocateVex(G,e);
        for(j=0; j<G.vexnum; j++)
            if(G.arcs[i][j].adj!=0)
                if(!Visited[j])
                {
                    Visited[j]=TRUE;
                    EnQueue(q,G.vexs[j]);
                }
        DeQueue(q,e);
        Visit(e);
    }
    printf("\n");
    return OK;
}
开发者ID:geroge-gao,项目名称:DataStructure,代码行数:31,代码来源:BFS.cpp

示例14: MapQueueMove

/* 
** MapQueueMove
** 
** Applies a function to each element in a queue.  If the function returns
** moveVal, it enqueues the element to q2, otherwise it requeues it to 
** the original queue.
*/
int MapQueueMove(QUEUE q, int (*pFunc)(void *, void**), void **argv, 
		 int moveVal, QUEUE q2) 
{
void *item;
int count = QueueCount(q);
int status = SUCCESS;

TypeCheck(q,TYPE_QUEUE);
TypeCheck(q2,TYPE_QUEUE);
assert(! IS_ERROR(moveVal));
while (count--)
   {
   item = DeQueue(q);
   if (NULL == item)
      return(-1);
   status = (*pFunc)(item,argv);
   if (IS_ERROR(status))
      return(status);
   if (status == moveVal)
      status = EnQueue(q2,item);
   else
      status = EnQueue(q,item);
   if (IS_ERROR(status))
      return(status);
   }
return(status);
}
开发者ID:huilang22,项目名称:Projects,代码行数:34,代码来源:queue.c

示例15: LevelOrderTraverse

 void LevelOrderTraverse(CSTree T,void(*Visit)(TElemType))
 { /* 层序遍历孩子-兄弟二叉链表结构的树T */
   CSTree p;
   LinkQueue q;
   InitQueue(&q);
   if(T)
   {
     Visit(Value(T)); /* 先访问根结点 */
     EnQueue(&q,T); /* 入队根结点的指针 */
     while(!QueueEmpty(q)) /* 队不空 */
     {
       DeQueue(&q,&p); /* 出队一个结点的指针 */
       if(p->firstchild) /* 有长子 */
       {
         p=p->firstchild;
         Visit(Value(p)); /* 访问长子结点 */
         EnQueue(&q,p); /* 入队长子结点的指针 */
         while(p->nextsibling) /* 有下一个兄弟 */
         {
           p=p->nextsibling;
           Visit(Value(p)); /* 访问下一个兄弟 */
           EnQueue(&q,p); /* 入队兄弟结点的指针 */
         }
       }
     }
   }
 }
开发者ID:githubzenganiu,项目名称:toekn,代码行数:27,代码来源:1-71.c


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