求大神帮我看看错哪里了·—·
#include<iostream>using namespace std;
typedef int Status;
typedef struct qnode
{
char name[20];
char sex;
struct qnode *next;
}qnode,*queueptr;
typedef struct
{
queueptr front; //队头指针
queueptr rear; //队尾指针
}Linkqueue;
Status Initqueue(Linkqueue &Q) //初始化
{
Q.front=Q.rear=new qnode;
Q.front->next=NULL;
return true;
}
Status enqueue(Linkqueue &Q,qnode e) //入队
{
queueptr p;
p=new qnode;
p->name=e.name;
p->sex=e.sex;
p->next=NULL;
Q.rear->next=p;
Q.rear=p;
return true;
}
Status dequeue(Linkqueue &Q,qnode &e) //出队
{
if(Q.front=Q.rear) return false;
queueptr p;
p=Q.front->next;
e.name=p->name;
e.sex=p->sex;
Q.front->next=p->next;
if(Q.rear==p) Q.rear=Q.front;
delete p;
return true;
}
queue gethead(Linkqueue Q) //取链队的队头元素
{
if(Q.front!=Q.rear)
return Q.front->next->name;
}
Status queue(Linkqueue Q)
{
if(Q.front->next==NULL)
return false;
}
char dancepartner()
{
int i,num=8;
qnode e,p;
Linkqueue Mdance,Fdance;
Initqueue(Mdance);
Initqueue(Fdance);
for(i=0;i<num;i++)
{
cin>>e.name;
cin>>e.sex;
p=e;
if(e.sex=='M') enqueue(Mdance,p);
else enqueue(Fdance,p);
}
cout<<"The dancing partners are:\n";
while(!queue(Mdance)&&!queue(Fdance))
{
dequeue(Fdance,e);
cout<<p.name<<" ";
dequeue(Mdance,e);
cout<<p.name<<endl;
}
if(!queue(Fdance))
{
p=gethead(Fdance);
cout<<"The first woman to get a partner is:"<<p.name<<endl;
}
else if(!queue(Mdance))
{
p=gethead(Mdance);
cout<<"The first man to get a partner is:"<<p.name<<endl;
}
}
main()
{
dancepartner();
}
这是输出舞伴的问题,求大神帮忙看看