- void Swap(int i,int j)
- {
- int temp = a[i];
- a[i] = a[j];
- a[j] = temp;
- }
- void lfs(int i,int n)
- {
- if (i < 0)
- {
- ncount++;
- for (int k = 0;k <= n;k++)
- {
- cout << a[k] << " ";
- }
- cout << endl;
- return;
- }
- for (int j = i;j <= n;j++)
- {
- Swap(i,j);
- lfs(i-1,n);
- Swap(j,i);
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/0402201511729.html
来源: http://www.codesnippet.cn/detail/0402201511729.html