C# 中的排序

来源:百度知道 编辑:UC知道 时间:2024/06/08 11:30:17
我所说的是组合排序
就是说给你一定的数字, 排列出不同的顺序来
比如说:
我这里有1、2 、3 三个数字,那么要求打印出他的六种不同的方试
1:1 2 3
2:1 3 2
3:2 1 3
4:2 3 1
5:3 1 2
6:3 2 1

要求用 C# 作, 请各位帮忙~~~
大家想的都不错, 可是我怎么感觉是给写死了,
如果说是输出5个数字, 或10个数字呢?

int []a =new int[]{1,2,3};

if (a.Length > 2)
{
for (int i = 0; i < a.Length; i++)
{
for (int j = 0; j < a.Length; j++)
{
if (i == j)
{
continue;
}
for (int c = 0; c < a.Length; c++)
{
if (c == i || c == j)
{
continue;
}
Console.WriteLine("" + a[i] + a[j] + [c]);
}
}
}
}

private static void pailie(int[] arr)
{
int sum = arr.Length;
int tmp = 1;