//LQueue.h 链式队列,不循环 #include "stdio.h" typedef struct qnode { DataType data; struct qnode *next; } LQNode; typedef struct { LQNode * front; LQNode * rear; } LQueue; void QueueInitiate(LQueue * Q) { Q->rear = NULL; Q->front = NULL; } int QueueNotEmpty(LQueue * Q) { if (Q->front == NULL) { return 0; } else { return 1; } } int QueueAppend(LQueue * Q, DataType x) { LQueue *p; if ((p == (LQNode *)malloc(sizeof(LQNode))) == NULL) { printf("内存空间不足!/n"); return 0; } else { p->data = x; p->next = NULL; if(Q->rear != NULL) Q->rear->next = p; //不是循环重贴队列,所以不用判断首尾重叠 Q->rear = p; if(Q->front == NULL) Q->front = p; return 1; } } QueueDelete(LQueue * Q, DataType * d) { LQNode *p; if (Q->front == NULL) { printf("队列为空,不能删除!/n"); return 0; } else { *d = Q->front->data; Q->front = Q->front->next; //并不是将地址付给他?而是直接定义为队首 if (Q->front == NULL) { Q->rear == NULL; } free(p); return 1; } } int QueueGet(LQueue * Q, DataType * d) { LQNode *p; if (Q->front == NULL) { printf("队列为空,不能取出!/n"); return 0; } else { *d = Q->front->data; return 1; } } void Destroy(LQueue *Q) { LQNode *p, *q; p = Q->front; while(p != NULL) { q = p; p = p->next; free(q); } }