一个有关用队列做舞伴的问题,请教下。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct nodetype
{
char name[10];
char sex;
struct nodetype *next;
}nodetype;
typedef struct
{
nodetype *front;
nodetype *rear;
}linkqueue;
nodetype *enter_queue(nodetype *p, linkqueue queue)
{
nodetype *s = NULL;
s = (struct nodetype *)malloc(sizeof(struct nodetype));
strcpy(s->name, p->name);
s->sex = p->sex;
s->next = NULL;
queue.rear->next = s; 调试到这一步就不行了,请问下是怎么了???????
return s;
}
nodetype *quit_queue(linkqueue queue)
{
nodetype *p;
printf("%s ", queue.front->name);
p = queue.front->next;
free(queue.front);
return p;
}
int main(void)
{
char ch, w;
nodetype person;
linkqueue man_queue, woman_queue;
man_queue.front = man_queue.rear = NULL;
woman_queue.front = woman_queue.rear = NULL;
printf("是否输入人员(Y/N):");
scanf("%c", &ch);
w = getchar();
while (ch == 'Y')
{
printf("请输入姓名:\n");
scanf("%s", &person.name);
w=getchar();
printf("请输入性别(F/M):\n");
scanf("%c", &person.sex);
if (person.sex = 'M')
{
man_queue.rear = enter_queue(&person, man_queue);
if(NULL == man_queue.front)
{
man_queue.front = man_queue.rear;
}
}
else
{
woman_queue.rear = enter_queue(&person, woman_queue);
if(NULL == woman_queue.front)
{
woman_queue.front = woman_queue.rear;
}
}
printf("是否输入人员(Y/N):");
w = getchar();
scanf("%c", &ch);
}
printf("男女舞伴配对为:\n");
while(man_queue.front != NULL && woman_queue.front != NULL)
{
man_queue.front = quit_queue(man_queue);
woman_queue.front = quit_queue(woman_queue);
printf("\n");
}
return 0;
}