/** * 广度优先搜索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); }
/* Libera fila da memoria. */ void DestroyQueue(Queue** Qe){ while(NotNullQueue(Qe)){ OutQueue(Qe); } free(*Qe); }
int AllocateTask(int thread_no) { while(1) { sem_wait(&pSems[thread_no]); debug_print(("allocating a event!\n")); pthread_mutex_lock(&mutex); tQueueNode * ptask = NULL; ptask = OutQueue(p); pthread_mutex_unlock(&mutex); ServerProcess(ptask->sockfd,ptask->pBuf); debug_print(("ServerProcess finish\n")); free(ptask); } }
int main() { queue q; initqueue(&q); showqueue(&q); printf("对尾插入元素...\n"); InQueue(&q,'a'); InQueue(&q,'b'); InQueue(&q,'c'); InQueue(&q,'d'); showqueue(&q); printf("队列中的元素个数为%d\n",Length(&q)); printf("队首删除元素..\n"); OutQueue(&q); showqueue(&q); return 0; }