全排列


#include<iostream>
using namespace std;

int data[4]={1,2,3,4};
int length=4;

void swap(int* data,int first,int second)
{
	int temp=data[first];
	data[first]=data[second];
	data[second]=temp;
}
void Permutate(int data[],int start,int end)
{
	if(start==end)
	{
		int i;
		for(i=0;i<length;i++)
			cout<<data[i]<<" ";
		cout<<endl;
		return;
	}

	int j;
	for(j=start;j<length;j++)
	{
		swap(data,start,j);
		Permutate(data,start+1,end);
		swap(data,start,j);
	}

}
void main()
{
	Permutate(data,0,length);
}



原文地址:https://www.cnblogs.com/pangblog/p/3299507.html