void Synchrone_Init(uint8_t mac) { uint8_t i; etat.state = WAIT_SCAN; //first time ;initialisation etat.ID_Network = NO_NETWORK; //no network at first etat.MAC = mac; etat.HOST = IS_NOT_CREATER ; etat.synchrone = 0; etat.ID_Beacon = 0; etat.Dst = 0; etat.Counter = 0; etat.Surveille_Cnt = 0; etat.Surveille_Cnt_Old = 0; InitQueue(&etat.FIFO_Send); InitQueue(&etat.FIFO_Recieve); Init_voisin(&etat); Init_route_table(&etat); //reset the table of route for(i = 0; i<N_SLOT-2; i++){ etat.check_old[i] = etat.check[i] = 0; } }
ProcessManager* InitProcessManager( ){ allocSpace = &procHeap; // Set mem location for procman and offset current location for further use ProcessManager* retval = falloc( sizeof(ProcessManager) ); // Initialize the process manager with appropriate values; // size represents the number of priorities retval->readyCount = 0; retval->memBlockCount = 0; retval->msgBlockCount = 0; retval->size = PROC_NUMPRIORITIES; retval->nextPid = 1; retval->nullProc = NULL; retval->interruptProc = NULL; retval->currentProc = NULL; // Allocate space for queues (4 levels each) and update current location pointer retval->ready = falloc( PROC_NUMPRIORITIES * sizeof(Queue) ); retval->memBlock = falloc( PROC_NUMPRIORITIES * sizeof(Queue) ); int i; // For each queue allocated, initialize queues for(i = 0; i < PROC_NUMPRIORITIES; i++ ){ InitQueue( &(retval->ready[i]) ); InitQueue( &(retval->memBlock[i]) ); } return retval; }
/** Reset the input device and optionally run diagnostics There are 2 types of reset for USB keyboard. For non-exhaustive reset, only keyboard buffer is cleared. For exhaustive reset, in addition to clearance of keyboard buffer, the hardware status is also re-initialized. @param This Protocol instance pointer. @param ExtendedVerification Driver may perform diagnostics on reset. @retval EFI_SUCCESS The device was reset. @retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset. **/ EFI_STATUS EFIAPI USBKeyboardReset ( IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, IN BOOLEAN ExtendedVerification ) { EFI_STATUS Status; USB_KB_DEV *UsbKeyboardDevice; UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This); REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_RESET), UsbKeyboardDevice->DevicePath ); // // Non-exhaustive reset: // only reset private data structures. // if (!ExtendedVerification) { REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, (EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_CLEAR_BUFFER), UsbKeyboardDevice->DevicePath ); // // Clear the key buffer of this USB keyboard // InitQueue (&UsbKeyboardDevice->UsbKeyQueue, sizeof (USB_KEY)); InitQueue (&UsbKeyboardDevice->EfiKeyQueue, sizeof (EFI_KEY_DATA)); InitQueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, sizeof (EFI_KEY_DATA)); return EFI_SUCCESS; } // // Exhaustive reset // Status = InitUSBKeyboard (UsbKeyboardDevice); if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } return EFI_SUCCESS; }
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); 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); } } } } } }
/** * 广度优先搜索for图 * @param {Graph} * @param {int} */ void BFS2 (Graph G, int pos) { int i = 0, temp; Queue Q; InitQueue(&Q); for (i = 0; i < G -> vexnum; i++) { //清零 IsRead[i] = 0; } if(IsRead[pos] == 0) { IsRead[pos] = 1; printf("遍历顶点:%c\n",G->vertex[pos]); } EnterQueue(Q, pos); // 当队列不为空 while (!isEmpty(Q)) { OutQueue(Q, &temp); for(i = 0; i< G->vexnum; i ++) { if(G->Arc[temp][i] != INFINITY && IsRead[i] == 0){ IsRead[i] = 1; printf("遍历顶点:%c\n",G->vertex[i]); EnterQueue(Q,i); } } } free(Q); }
Status CreateBiTree(BiPTree *T) { /* 按先序次序输入二叉树中结点的值(可为字符型或整型,在主程中定义), */ /* 构造三叉链表表示的二叉树T */ LinkQueue q; QElemType a; Create(T); /* 构造二叉树(缺双亲指针) */ if(*T) /* 非空树 */ { (*T)->parent=NULL; /* 根结点的双亲为"空" */ InitQueue(&q); /* 初始化队列 */ EnQueue(&q,*T); /* 根指针入队 */ while(!QueueEmpty(q)) /* 队不空 */ { DeQueue(&q,&a); /* 出队,队列元素赋给a */ if(a->lchild) /* 有左孩子 */ { a->lchild->parent=a; /* 给左孩子的双亲指针赋值 */ EnQueue(&q,a->lchild); /* 左孩子入队 */ } if(a->rchild) /* 有右孩子 */ { a->rchild->parent=a; /* 给右孩子的双亲指针赋值 */ EnQueue(&q,a->rchild); /* 右孩子入队 */ } } } return OK; }
TElemType Parent(BiTree T,TElemType e) { /* 初始条件: 二叉树T存在,e是T中某个结点 */ /* 操作结果: 若e是T的非根结点,则返回它的双亲,否则返回"空" */ LinkQueue q; QElemType a; if(T) /* 非空树 */ { InitQueue(&q); /* 初始化队列 */ EnQueue(&q,T); /* 树根入队 */ while(!QueueEmpty(q)) /* 队不空 */ { DeQueue(&q,&a); /* 出队,队列元素赋给a */ if(a->lchild&&a->lchild->data==e||a->rchild&&a->rchild->data==e) /* 找到e(是其左或右孩子) */ return a->data; /* 返回e的双亲的值 */ else /* 没找到e,则入队其左右孩子指针(如果非空) */ { if(a->lchild) EnQueue(&q,a->lchild); if(a->rchild) EnQueue(&q,a->rchild); } } } return Nil; /* 树空或没找到e */ }
void main(char** args) { TCB_t* threads[READER + WRITER]; puts("initializing semaphores and threads"); srand(time(NULL)); mutex = malloc(sizeof(SEM_t)); rsem = malloc(sizeof(SEM_t)); wsem = malloc(sizeof(SEM_t)); InitSem(mutex, 1); InitSem(rsem, 0); InitSem(wsem, 0); InitQueue(&runQ); int i = 0, j = 0, h = 0; while (i < READER + WRITER) { int r = rand() % 2; if (j < READER && r == 0) { puts("Adding reader"); start_thread(threads[i], reader); i++; j++; } if (h < WRITER && r == 1) { puts("Adding writer"); start_thread(threads[i], writer); i++; h++; } } puts("runQ content:"); printQueue(runQ); puts("\nstarting threads\n"); run(); }
static 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); // 入队兄弟结点的指针 } } } } }
void bfs(Edge **C, int nNodes, int sink, int *sequenceList) { int *colour; Item u, v, *p; Item i = 0; int k = 0; p = (Item *)malloc(sizeof(Item)); colour = (int *)calloc(nNodes, sizeof(int)); colour[sink] = GRAY; Queue *queue = InitQueue(); EnQueue(queue, sink); do { while (!IsEmpty(queue)) { DeQueue(queue, p); sequenceList[k++] = v = *p; for (u = 0; u < nNodes; u++) { if (colour[u] == WHITE && C[u][v].eContent > 0) { EnQueue(queue, u); colour[u] = GRAY; } } colour[v] = BLACK; } if (colour[i] == WHITE) { EnQueue(queue, i); colour[i] = GRAY; } } while(i++ < nNodes); free(p); free(colour); DestroyQueue(queue); }
int main() { SeQueue Q; int data = 3, value; //0. Init InitQueue(Q); PrintQueue(Q); //1. Enter Queue printf("\n"); PrintQueue(Q); printf("EnQueue = %d\n", data); EnQueue(Q, data); PrintQueue(Q); //2. DeQueue printf("\n"); PrintQueue(Q); value = Front(Q); DeQueue(Q); printf("DeQueue value = %d\n", value); PrintQueue(Q); //3. Clear printf("\n"); PrintQueue(Q); printf("Clear Queue\n"); ClearQueue(Q); PrintQueue(Q); return 0; }
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; }
TElemType Parent(BiTree T,TElemType e) { // 初始条件: 二叉树T存在,e是T中某个结点 // 操作结果: 若e是T的非根结点,则返回它的双亲,否则返回"空" LinkQueue q; QElemType a; if(T) // 非空树 { InitQueue(q); // 初始化队列 EnQueue(q,T); // 树根入队 while(!QueueEmpty(q)) // 队不空 { DeQueue(q,a); // 出队,队列元素赋给a if(a->lchild&&a->lchild->data==e||a->rchild&&a->rchild->data==e) // 找到e(是其左或右孩子) return a->data; // 返回e的双亲的值 else // 没找到e,则入队其左右孩子指针(如果非空) { if(a->lchild) EnQueue(q,a->lchild); if(a->rchild) EnQueue(q,a->rchild); } } } return Nil; // 树空或没找到e }
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); /* 入队兄弟结点的指针 */ } } } } }
TElemType Parent(CSTree T,TElemType cur_e) { /* 初始条件: 树T存在,cur_e是T中某个结点 */ /* 操作结果: 若cur_e是T的非根结点,则返回它的双亲,否则函数值为"空" */ CSTree p,t; LinkQueue q; InitQueue(&q); if(T) /* 树非空 */ { if(Value(T)==cur_e) /* 根结点值为cur_e */ return Nil; EnQueue(&q,T); /* 根结点入队 */ while(!QueueEmpty(q)) { DeQueue(&q,&p); if(p->firstchild) /* p有长子 */ { if(p->firstchild->data==cur_e) /* 长子为cur_e */ return Value(p); /* 返回双亲 */ t=p; /* 双亲指针赋给t */ p=p->firstchild; /* p指向长子 */ EnQueue(&q,p); /* 入队长子 */ while(p->nextsibling) /* 有下一个兄弟 */ { p=p->nextsibling; /* p指向下一个兄弟 */ if(Value(p)==cur_e) /* 下一个兄弟为cur_e */ return Value(t); /* 返回双亲 */ EnQueue(&q,p); /* 入队下一个兄弟 */ } } } } return Nil; /* 树空或没找到cur_e */ }
extern void InitCG( void ) /****************************/ { InOptimizer = 0; InsId = 0; CurrProc = NULL; CurrBlock = NULL; BlockList = NULL; HeadBlock = NULL; BlockByBlock = FALSE; abortCG = FALSE; InitFP();/* must be before InitRegTbl */ InitRegTbl(); ScoreInit(); InitQueue(); InitMakeAddr(); RegTreeInit(); InitIns(); InitConflict(); InitRT(); InitNames(); ObjInit(); ClassPointer = TypeClass( TypePtr ); InitSegment(); }
static TElemType Parent(CSTree T,TElemType cur_e) { // 初始条件: 树T存在,cur_e是T中某个结点 // 操作结果: 若cur_e是T的非根结点,则返回它的双亲,否则函数值为"空" CSTree p,t; LinkQueue q; InitQueue(q); if(T) // 树非空 { if(Value(T)==cur_e) // 根结点值为cur_e return Nil; EnQueue(q,T); // 根结点入队 while(!QueueEmpty(q)) { DeQueue(q,p); if(p->firstchild) // p有长子 { if(p->firstchild->data==cur_e) // 长子为cur_e return Value(p); // 返回双亲 t=p; // 双亲指针赋给t p=p->firstchild; // p指向长子 EnQueue(q,p); // 入队长子 while(p->nextsibling) // 有下一个兄弟 { p=p->nextsibling; // p指向下一个兄弟 if(Value(p)==cur_e) // 下一个兄弟为cur_e return Value(t); // 返回双亲 EnQueue(q,p); // 入队下一个兄弟 } } } } return Nil; // 树空或没找到cur_e }
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; }
//把出现过的字符编码表经过压缩写进文件 short CodeToFile(FILE *fp,char **hc,short n,SeqQueue *Q,MyType *length) { int i; char *p; MyType j,bits; short count=0; for(i = 0;i < n;i++)// 将n个叶子压缩并写入文件 { for(p = hc[i]; '\0' != *p; p++) In_seqQueue( Q,*p ); while(Q->length > 8) { bits = GetBits(Q);//出队8个元素 fputc(bits,fp); count++; } } *length = Q->length; i = 8 - *length; bits = GetBits(Q);//取8个如果队不空 for(j = 0;j < i;j++) bits = bits << 1; fputc(bits,fp); count++; InitQueue(Q); return count; }
void LevelOrderTraverse(CSTree T, void (*Visit)(TElemType)) { 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); } } } } printf("\n"); }
void BFSTraverse(OLGraph G,Status(*Visit)(VertexType)) { /* 初始条件: 有向图G存在,Visit是顶点的应用函数。算法7.6 */ /* 操作结果: 从第1个顶点起,按广度优先非递归遍历有向图G,并对每个顶点调用 */ /* 函数Visit一次且仅一次。一旦Visit()失败,则操作失败。 */ /* 使用辅助队列Q和访问标志数组visited */ int v,u,w; VertexType u1,w1; SqQueue Q; for(v=0;v<G.vexnum;v++) visited[v]=FALSE; InitQueue(&Q); for(v=0;v<G.vexnum;v++) if(!visited[v]) { visited[v]=TRUE; Visit(G.xlist[v].data); EnQueue(&Q,v); while(!QueueEmpty(Q)) { DeQueue(&Q,&u); strcpy(u1,*GetVex(G,u)); for(w=FirstAdjVex(G,u1);w>=0;w=NextAdjVex(G,u1,strcpy(w1,*GetVex(G,w)))) if(!visited[w]) /* w为u的尚未访问的邻接顶点的序号 */ { visited[w]=TRUE; Visit(G.xlist[w].data); EnQueue(&Q,w); } } } printf("\n"); }
/* 邻接矩阵的广度遍历算法 */ 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); /* 将找到的此顶点入队列 */ } } } } } }
void main() { LinkQueue *lq; ElemType e; InitQueue(lq); printf("队%s\n", (QueueEmpty(lq) == 1 ? "空" : "不空")); printf("a进队\n"); EnQueue(lq, 'a'); printf("b进队\n"); EnQueue(lq, 'b'); printf("c进队\n"); EnQueue(lq, 'c'); printf("d进队\n"); EnQueue(lq, 'd'); printf("队%s\n", (QueueEmpty(lq) == 1 ? "空" : "不空")); GetHead(lq, e); printf("队头元素:%c\n", e); printf("出队次序:"); while (!QueueEmpty(lq)) { DeQueue(lq, e); printf("%c ", e); } printf("\n"); }
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; }
//测试单链队列的主程序 int main() { SqQueue s; int x; //输入若干正整数以0结束,依次入栈,然后依次出栈并打印 InitQueue(&s); printf("Is empty: %d\n",IsEmpty(s)); printf("the length is: %d\n",QueueLength(s)); printf("进入队列顺序: 1 2 3 \n"); EnQueue(&s,1); EnQueue(&s,2); EnQueue(&s,3); printf("the top is : %d\n",x); printf("Is empty: %d\n",IsEmpty(s)); printf("the length is: %d\n",QueueLength(s)); printf("\n退出队列结果:"); while(!IsEmpty(s)) { DEQueue(&s,&x); printf("%4d",x); } printf("\nIs empty: %d\n",IsEmpty(s)); //------------------------------------- // TODO (#1#): 其它测试程序 //------------------------------------- DestroyQueue(&s); //销毁栈 return 0; }
/* * initialize the hash table structure and the related lock for each table. */ void InitRecord(void) { InitBucketNum_Size(); InitRecordNum(); InitRecordMem(); InitLatchMem(); int i; uint64_t j; for (i = 0; i < TABLENUM; i++) { for (j = 0; j < RecordNum[i]; j++) { InitQueue(&TableList[i][j]); } } for (i = 0; i < TABLENUM; i++) { for (j = 0; j < RecordNum[i]; j++) { pthread_rwlock_init(&(RecordLock[i][j]), NULL); pthread_spin_init(&(RecordLatch[i][j]), PTHREAD_PROCESS_PRIVATE); } } }
//----------------------------Breadth First Search --------------------------------// Status BFSTraverse( AMLGraph G , Status ( *v )( VertexType v ) ) { int u , w , q; LinkQueue Q ; for( u = 0 ; u < G.vexnum ; ++ u ) //如果利用数据结构本身的访问标志域会very good! { visite[ u ] = FALSE ; } InitQueue( &Q ) ; for( u = 0 ; u < G.vexnum ; ++ u ) { if( !visite[ u ] ) //u尚未被访问 { visite[ u ] = TRUE ; v( G.adjmulist[ u ].data ) ; EnQueue( &Q , u ) ; //u号入队列 while( !QueueEmpty( Q ) ) { DeQueue( &Q , &q ) ; for( w = FirstAdjVex( G , G.adjmulist[ q ].data ) ; w >= 0 ; w = NextAdjVex( G , G.adjmulist[ q ].data , G.adjmulist[ w ].data ) ) if( !visite[ w ] ) //w为q的尚未访问的邻接顶点 { visite[ w ] = TRUE ; v( G.adjmulist[ w ].data ) ; EnQueue( &Q , w ) ; } }//while }//if }//for return OK ; }
void BFSTraverse(AMLGraph G,Status(*Visit)(VertexType)) { /* 初始条件: 图G存在,Visit是顶点的应用函数。*/ /* 操作结果: 从第1个顶点起,按广度优先非递归遍历图G,并对每个顶点调用函数 */ /* Visit一次且仅一次。一旦Visit()失败,则操作失败。 */ /* 使用辅助队列Q和访问标志数组visite */ int v,u,w; VertexType w1,u1; LinkQueue Q; for(v=0;v<G.vexnum;v++) visite[v]=FALSE; /* 置初值 */ InitQueue(&Q); /* 置空的辅助队列Q */ for(v=0;v<G.vexnum;v++) if(!visite[v]) /* v尚未访问 */ { visite[v]=TRUE; /* 设置访问标志为TRUE(已访问) */ Visit(G.adjmulist[v].data); EnQueue(&Q,v); /* v入队列 */ while(!QueueEmpty(Q)) /* 队列不空 */ { DeQueue(&Q,&u); /* 队头元素出队并置为u */ strcpy(u1,*GetVex(G,u)); for(w=FirstAdjVex(G,u1);w>=0;w=NextAdjVex(G,u1,strcpy(w1,*GetVex(G,w)))) if(!visite[w]) /* w为u的尚未访问的邻接顶点的序号 */ { visite[w]=TRUE; Visit(G.adjmulist[w].data); EnQueue(&Q,w); } } } printf("\n"); }
int main() { LinkQueue Q; QElemType e = 5; InitQueue(&Q); EnQueue(&Q,e); TranverseQueue(Q,print); printf("\n------------\n"); e = 6; EnQueue(&Q,e); TranverseQueue(Q,print); printf("\n------------\n"); e = 7; EnQueue(&Q,e); TranverseQueue(Q,print); printf("\n------------\n"); DeQueue(&Q,&e); TranverseQueue(Q,print); DestroyQueue(&Q); return 0; }
void BFSTraverse(GraphAdjList GL) { int i; EdgeNode *p; Queue Q; for(i=0; i<GL->numVertexes; i++) visited[i]=FLASE; InitQueue(&Q); for(i=0; i<GL->numVertexes; i++) { if(!visited[i]) { visited[i]=TRUE; printf("%c ",GL->adjList[i].data); EnQueue(&Q,i); while(!QueueEmpty(Q)) { DeQueue(&Q,&i); p=GL->adjList[i].firstedge; //找到当前顶点边表链表头指针 while(p) { if(!visited[p->adjvex]) //若此顶点未被访问 { visited[p->adjvex]=TRUE; printf("%c ",GL->adjList[p->adjvex].data); EnQueue(&Q,p->adjvex); } p=p->next; } } } } }