//---------单链队-队列的链式存储------------
#include<stdio.h>
#include<stdlib.h>
typedef int QElemType;
typedef struct QNode {
QElemType data;
struct QNode *next;
}QNode,*QueuePtr;
typedef struct {
QueuePtr front ;
QueuePtr rear;
}LinkQueue;
int InitQueue(LinkQueue Q) {
Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode));
if(!Q.front) exit(0);
Q.front->next=NULL;
return 1;
}
int DestoryQueue(LinkQueue &Q) {
while(Q.front)
{
Q.rear=Q.front->next;
free(Q.front);
Q.front=Q.rear;
}
return 1;
}
int EnQueue(LinkQueue &Q,QElemType e) {
QueuePtr p;
p=(QueuePtr)malloc(sizeof(QNode));
if(!p) exit(0);
p->data=e;p->next=NULL;
Q.rear->next=p;
Q.rear=p;
return 1;
}
int DeQueue(LinkQueue &Q,QElemType &e){
QueuePtr p;
if(Q.front==Q.rear) return 0;
p=Q.front->next;
e=p->data;
Q.front->next=p->next;
if(Q.front==p) Q.rear=Q.front;
free(p);
return 1;
}
void main()
{
LinkQueue Q;
QElemType e;
InitQueue(Q);
EnQueue(Q,1);
EnQueue(Q,1);
DeQueue(Q,e);
}