- 排队找舞伴的问题可以转化为队列问题,分男女构建两个队列,通过性别判断跳舞者放进哪个队列。
- 在代码实现中,我采用文件输入的方式将跳舞者的名字和性别赋值给dancer数组,再通过传数组的方式将Dancer入队。
- 在完成书本任务的同时,我改进解决方案,使舞者可以循环配对寻找舞伴
!!!注意,cv代码时,需要自己在项目下建立一个txt文件,里面是跳舞人员信息。这样才能正常运行
1.#include <iostream>
2.#include <fstream>
3.#define MaxSize 100
4.#define ERROR 0
5.#define OK 1
6.using namespace std;
7.typedef int Status;
8.typedef struct
9.{
10. char name[20];
11. char sex;
12.}Dancer;
13.typedef struct
14.{
15. Dancer *base;
16. int front;
17. int rear;
18.}SqQueue;
19.Status InitQueue(SqQueue &Q)
20.{
21. Q.base=new