#include<stdio.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define N 100
typedef int Status;
typedef int ElemType;
typedef struct QNode{
ElemType data;
struct QNode *next;
}QNode,* QueuePtr;
typedef struct{
QueuePtr front;
QueuePtr rear;
}LinkQueue;
Status Init_Sq(LinkQueue &Q){
Q.front=Q.rear=(QNode *)malloc(sizeof(QNode));
Q.front->next=NULL;
return OK;
}
Status Inser_Sq(LinkQueue &Q,ElemType e){
QNode *p;
p=new QNode;
p->data=e;
p->next=NULL;
Q.rear->next=p;
Q.rear=p;
return OK;
}
ElemType Pop_Sq(LinkQueue &Q){
if(Q.front==Q.rear) return ERROR;
ElemType e=Q.front->next->data;
Q.front->next=Q.front->next->next;
if(Q.rear==Q.front->next) Q.rear=Q.front;
return e;
}
int main(){
LinkQueue Q;
Init_Sq(Q);
Inser_Sq(Q,4);
Inser_Sq(Q,1);
Inser_Sq(Q,2);
ElemType e=Pop_Sq(Q);
printf("%d\n",e);
ElemType e1=Pop_Sq(Q);
printf("%d\n",e1);
ElemType e2=Pop_Sq(Q);
printf("%d\n",e2);
}
为什么这样不对,输出是4(换行)1(换行)0