本文整理匯總了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入隊列
}
}
}
}
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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); /* 將找到的此頂點入隊列 */
}
}
}
}
}
}
示例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;
}
示例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++;
}
}
示例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");
}
}
示例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;
}
示例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);
}
}
}
示例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入隊列 */
}
}
}
示例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;
}
示例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;
}
示例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);
}
示例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); /* 入隊兄弟結點的指針 */
}
}
}
}
}