#include<iostream>
using namespace std;
typedef struct{
int id;
char name[10];
}QElemtype;
typedef struct qNode{
QElemtype data;
struct qNode *next;
}qNode,*QueuePtr;
typedef struct{
qNode *front;
qNode *rear;
}LinkQueue;
void InitQueue(LinkQueue &Q);
void EnQueue(LinkQueue &Q,QElemtype e);
void DeQueue(LinkQueue &Q);
int QueueEmpty(LinkQueue &Q);
void OutQueue(LinkQueue Q);
int main(){
LinkQueue s;
QElemtype newdata;
InitQueue(s);
int n;
cout << "请输入链队的长度:" << endl;
cin >> n;
for(int i=1;i<=n;i++){
cout << "输入链队的第" << i << "个元素" << endl;
cin >> newdata.id >> newdata.name;
EnQueue(s,newdata);
}
//cout << "请输出元素:" << endl;
OutQueue(s);
while (!QueueEmpty(s))
{
DeQueue(s);
}
return 0;
}
//链队的初始化
void InitQueue(LinkQueue &Q){
Q.front=Q.rear=new qNode;
Q.front->next=NULL;
}
//入队
void EnQueue(LinkQueue &Q,QElemtype e){
QueuePtr p;
p=new qNode;
p->data=e;
p->next=NULL;
Q.rear=p;
}
//出队
void DeQueue(LinkQueue &Q){
QueuePtr p;
if(Q.front==Q.rear)
exit(1);
p=Q.front->next;
QElemtype &e=p->data;
Q.front->next=p->next;
if(Q.rear==p)
Q.rear=Q.front;
delete(p);
}
//判断栈是否为空
int QueueEmpty(LinkQueue &Q){
if (Q.front==Q.rear)
return 1;
else
return 0;
}
//遍历输出
void OutQueue(LinkQueue Q){
qNode *s;
s=Q.front->next;
if(!s)
cout << "is empty!" << endl;
else
cout << "元素输出:"<< endl;
while(s){
printf("%d",s->data);
s=s->next;
}
cout << endl;
}
想输出结果,结果就是出不来……