标签:
#include<cstdio> #include<cstdlib> #include<cstring> typedef struct Qnode{ int data; struct Qnode *next; }Qnode,*QueuePtr; typedef struct{ QueuePtr front,rear; }LinkQueue; void Init(LinkQueue *Q){ Q->front = (QueuePtr)malloc(sizeof(Qnode)); Q->rear = Q->front; } int EnQueue(LinkQueue *Q,int e){ QueuePtr s = (QueuePtr)malloc(sizeof(Qnode)); if(!s) exit(0); s->data = e; s->next = NULL; Q->rear->next = s; Q->rear = s; printf("已将 %d 入队!\n",e); return 1; } int DeQueue(LinkQueue *Q,int *e){ QueuePtr p; if(Q->front == Q->rear) return 0; p = Q->front->next; *e = p->data; Q->front->next = p->next; if(Q->rear == p) Q->rear = Q->front; free(p); return 1; } int main(){ LinkQueue Q; int e; Init(&Q); for(int i=1;i<=10;i++){ EnQueue(&Q,i); } for(int i=0;i<10;i++){ DeQueue(&Q,&e); printf(" %d\n",e); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zhuozhuo/p/5408625.html