#include #include using namespace std; struct dancer // 舞者信息 { string name; // 姓名 char sex; // 性别 }; struct Node // 队列结点 { dancer data; // 数据域 Node* next; // 指针域,指向后继 }*front,*rear; // 队头、队尾 struct LinkQueue { Node *front; Node *rear; }; // 男队和女队 void InitialLinkQueue(LinkQueue &Q) // 初始化队列 { Q.front=new Node; Q.front->next=NULL; Q.rear=Q.front; } void DestroyLinkQueue(LinkQueue &Q) // 销毁队列 { Node *p; while(Q.front!=NULL) { p=Q.front; Q.front=Q.front->next; delete p; } } void EnQueue(LinkQueue &Q,dancer &e) // 入队 { Node *s=new Node; s->data=e; s->next=Q.rear->next; Q.rear->next=s; Q.rear=s; } bool IsEmpty(LinkQueue Q) // 判队空 { if (Q.front==Q.rear) return true; else return false; } bool DeQueue(LinkQueue &Q,dancer &e) // 出队 { Node *p; if (IsEmpty(Q)) // 队空, { cout<<"队列为空,无法出队列!"; return false; } p=Q.front->next; e=p->data; Q.front->next=p->next; if (p==Q.rear) // 只有一个元素,出队 Q.rear=Q.front; // 修改队尾指针 delete p; return true; } bool GetHead(LinkQueue Q,dancer &e) { if(IsEmpty(Q)) // 队空 { cout<< "队列为空,无法取得队首元素!"; return false; } e=Q.front->next->data; // 返回队头元素 return true; } void QueueTranverse(LinkQueue Q) // 遍历队 { Node *p; p=Q.front->next; while(p!=NULL) { cout<<(p->data).name<<" "; p=p->next; } cout<>person[i].sex; cin>>person[i].name; } cout<<"现有舞者:"<"<>num; person=new dancer[num]; EntranHall(person, num); // 舞者入场 DancePartner(person,num); // 舞者匹配 return 0; }