满意答案
aikeni521
2017.04.11
采纳率:59% 等级:8
已帮助:463人
#include using namespace std; #define OK 1 #define ERROR 0 #define OVERFLOW -1 typedef int QElemType; typedef int status; typedef struct QNode{ QElemType data; struct QNode *next; }QNode,*QueuePtr; typedef struct{ QueuePtr front; QueuePtr rear; }LinkQueue; status InitQueue(LinkQueue &Q) { Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode)); if(!Q.front) exit(OVERFLOW); Q.front->next=NULL; return OK; } status DestroyQueue(LinkQueue &Q) { while(Q.front) { Q.rear=Q.front->next; free(Q.front); Q.front=Q.rear; } return OK; } status EnQueue(LinkQueue &Q,QElemType e) { QueuePtr p; p=(QueuePtr)malloc(sizeof(QNode)); if(!p) return OVERFLOW; p->data=e; p->next=NULL; Q.rear->next=p; Q.rear=p; return OK; } status DeQueue(LinkQueue &Q,QElemType &e) { QueuePtr p; if(Q.front==Q.rear) return ERROR; p=Q.front->next; e=p->data; Q.front->next=p->next; if(Q.rear==p) Q.front==Q.rear; free(p); return OK; } status QueueLength(LinkQueue Q,QElemType &i) { QueuePtr p; i=0; if(Q.front==Q.rear) return ERROR; p=Q.front->next; while(p!=NULL) { i++; p=p->next; } return OK; } status GetHead(LinkQueue Q,QElemType &e) { QueuePtr p; if(Q.front==Q.rear) return ERROR; p=Q.front->next; e=p->data; return OK; } void QueueTraverse(LinkQueue Q) { QueuePtr p; int e; p=Q.front->next; while(p!=NULL) { e=p->data; cout<
110分享举报