有N 个序号:0, 1, 2... N-1
其全排序有N!种
如何用简单的办法生成全部排序?
static
int
[] a
=
...
{0,1,2,3,4,5}
;
static
int
n
=
6
;

static
void
swap(
int
arg1,
int
arg2)

...
{
int temp;
temp = a[arg1];
a[arg1] = a[arg2];
a[arg2] = temp;
}
static
void
sort(
int
index)

...
{
int i;

if (index == n)

...{
for (i = 0; i < n; i++)

...{
System.out.print(a[i]);
System.out.print(" ");
}
System.out.println("");
return;
}
for (i = index; i < n; i++)

...{
swap(index,i);
sort(index + 1);
swap(index,i);
}
}