3个数的全排列 [递归]

#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
int n, p[10], hashtable[10] = { 0 };
using namespace std;
void digui(int index)
{
	if (index == n + 1)
	{
		for (int i = 1; i <=n; i++)
		{
			cout << p[i];
		}
		cout << endl;
		return;
	}
	for (int x = 1; x <= n; x++)
	{
		if (hashtable[x] == false)
		{
			p[index] = x;
			hashtable[x] = true;
			digui(index + 1);
			hashtable[x] = false;
		}
	}
}
int main()
{
	n = 4;
	digui(1);
	return 0;
}

posted @ 2020-07-08 20:22  _Hsiung  阅读(238)  评论(0编辑  收藏  举报