#include
#include
#include
#include
#include
#include
#include
#include
#include
#define N 100
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
typedef int Status;
typedef int Boolean;
typedef struct
{
char sex;
char name[20];
}Person;
typedef Person DataType;
#define MAXQSIZE 100
#define QUEUEINCREMENT 2
typedef struct
{
Person *base;
int front;
int rear;
}SqQueue;
char InitQueue(SqQueue *Q)
{//构造一个空队列Q
(*Q).base=(DataType *)malloc(MAXQSIZE*sizeof(DataType));
if(!(*Q).base)
printf("OVERFLOW\n");
(*Q).front=(*Q).rear=0;
return OK;
}
Status QueneEmpty(SqQueue *Q)
{
if((*Q).front==(*Q).rear)
return TRUE;
else
return FALSE;
}
Status EnQuene(SqQueue *Q,DataType e)
{
if(((*Q).rear+1)%MAXQSIZE==(*Q).front)
{
return ERROR;
}
(*Q).base[(*Q).rear]=e;
(*Q).rear=((*Q).rear+1)%MAXQSIZE;
return OK;
}
Status DeQuene(SqQueue *Q,DataType e)
{
if((*Q).front==(*Q).rear)
return ERROR;
e=(*Q).base[(*Q).front];
(*Q).front=((*Q).front+1)%MAXQSIZE;
return OK;
}
Person Gethead(SqQueue *Q)
{
if((*Q).front!=(*Q).rear)
return (*Q).base[(*Q).front];
else
exit(0);
}
void DancePartner(Person dancer[],int num)
{
Person p;
SqQueue Mdancers,Fdancers;
int i;
InitQueue(&Mdancers);
InitQueue(&Fdancers);
for(i=0;i<num;i++)
{
p=dancer[i];
if(p.sex=='F')
EnQuene(&Fdancers,p);
else
EnQuene(&Mdancers,p);
}
printf("the danceing partner are: \n");
while(!QueneEmpty(&Fdancers)&&!QueneEmpty(&Mdancers));
{
DeQuene(&Fdancers,p);
printf("%s",p.name);
DeQuene(&Mdancers,p);
printf("%s",p.name);
}
if(!QueneEmpty(&Fdancers));//输出女士剩余人数及队头女士的名字
{
p=Gethead(&Fdancers);
printf("%s will be the first to get a partner \n",dancer[i].name);
}
if(!QueneEmpty(&Mdancers))
{
p=Gethead(&Mdancers);
printf("%s will be the first to get a partner \n",dancer[i].name);
}
}
int main()
{
Person dancers[N];
int i,num;
printf("输入跳舞总人数:\n");
scanf("%d",&num);
printf("输入姓名和性别:\n");
for(i=0;i<num;i++)
{
scanf("%s",&dancers[i].name[20]);
getchar();
scanf("%c",&dancers[i].sex);
}
DancePartner(&dancers[N],num);
return 0;
}
程序正确,没有错误,警告。但是不能输出结果