#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
typedef int datatype;
typedef struct QNode
{
datatype data;
struct QNode *next;
}QNode;
typedef struct qptr
{
QNode *front; //队头指针
QNode * rear; //队尾指针
} LinkQueue;
int InitQueue(LinkQueue* &Q)
{
Q=new LinkQueue;
Q->front=NULL;
Q->rear=NULL;
return 1;
}
int QueueEmpty(LinkQueue* Q)
{
if(Q->front=NULL)
{
return 1;
}
else
return 0;
}
int InQueue(LinkQueue* Q,datatype x)
{
QNode *s;
s=new QNode;
s->data=x;
s->next=NULL;
if(Q->front==NULL)
{
Q->front=Q->rear=s;
}
else
{
Q->rear->next=s;
s=Q->rear;
}
return 1;
}
int OutQueue(LinkQueue* Q,datatype &x)
{
QNode *p;
if(Q->front==NULL) return 0;
p=Q->front;
x=p->data;
if(Q->front==Q->rear&&Q->rear!=NULL)
{
Q->front=Q->rear=NULL;
}
else
{
Q->front=Q->front->next;
}
free (p);
return 1;
}
int main()
{
LinkQueue* Q;
int n;
datatype x;
while(1)
{
cout<<"请选择: 1 创建新队列 2 入队 3 出队 0 结束"<<endl;
scanf("%d",&n);
if(n==1)
{
if(InQueue(Q,x)==1)
cout<<"创建成功\n"<<endl;
}
else if(n==2)
{
scanf("%d",&x);
if (InQueue(Q,x)==1)
cout<<"入队成功\n"<<endl;
else
cout<<"入队失败\n"<<endl;
}
else if(n==3)
{
if(OutQueue(Q,x)==1)
{
cout<<x<<endl;
cout<<"出队成功\n"<<endl;
}
else
cout<<"出队失败\n"<<endl;
}
else if(n==0)
break;
}
}
n你输入了几啊,没运行结束?