平坝有什么好吃的:谁能告诉我如何用c语言编写数据结构中的舞伴问题

来源:百度文库 编辑:高考问答 时间:2024/04/30 01:25:48
包括头文件.谢谢!最后能运行出来的!!我不胜感谢,并付出我所有的积分!

typedef struct{
char name[20];
char sex;
}Person;
typedef Person DataType;

void DancePartners(Person dancer[],int num)
{
int i;
Person p;
CirQueue Mdancers,Fdancers;
InitQueue(&Mdancers);
InirQueue(&Fdancers);
for(i=0;i<num;i++){
p=dancer[i];
if(p.sex=='F')
EnQueue(&Fdancers,p);
else
EnQueue(&Mdancers,p);
}
printf("The dancing partners are:\n\n");
while(!QueueEmpty(&Fdancers)&&!QueueEmpty (&Mdancers)){
p=DeQueue(&Fdancers);
printf("%s ",p.name);
p=DeQueue(&Mdancers);
printf("%s\n",p.name);
}
if(!QueueEmpty(&Fdancers)){
printf("\nThere are %d women waiting for the next round.\n",Fdancers.count);
p=QueueFront(&Fdancers);
printf("%s will be the first to get a partner.\n",p.name);
}else
if(!QueueEmpty(&Mdancers)){
printf("\nThere are %d men waiting for the next round.\n",Mdancers.count);
p=QueueFront(&Mdancers);
printf("%s will be the first to get a partner.\n",p.name);
}
}