以下裁判程序输出正整数1~n的全排列。
本题需要实现如下函数bfs()并在其中调用裁判测试程序中的EnQueue()函数,完成使用队列式广度优先搜索全排列问题的排列树。
函数接口定义:
void bfs(); //广度优先搜索排列树
裁判测试程序样例:
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
vector<int> nSet; // 原始元素集合
int n; // 原始元素个数
struct NodeType //队列中的结点类型
{
int i; //当前结点在搜索空间中的层次
vector<int> x; //当前结点包含的解向量(排列结果)
vector<bool> used; //当前各元素是否已用于排列的情况
};
void EnQueue(NodeType e, queue<NodeType> &qu) //结点e是否进队qu及相应处理
{
if (e.i==n){ //若e为叶子结点,不进队,对应一种排列
for(int j = 0; j < n; j++){
cout<<e.x[j];
}
co