对给定数组进行全排,这个代码问题知道,但不晓得怎么改,大家帮看看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6 {
class Program {
static void Main(string[] args) {
Search(target);
}
static int[] target = new int[] { 1,3,5,7 };
static int[] current = new int[target.Length];
static List<int[]> resault = new List<int[]>();
static int mark = 0;
static void SetCurrent(int[] x,int position) {
current[mark++] = x[position];
if (mark == target.Length) {
resault.Add(current);
current = new int[target.Length];
mark = 0;
}
}
static int[] BuildIndex(int[] x) {
int[] r = new int[x.Length];
for (int i = 0 ; i < x.Length ; i++) {
r[i] = i;
}
return r;
}
//static int[] index = default(int[]);
static int[] Get1(int[] x,int p) {
int[] r = default(int[]);
var index = BuildIndex(x);
var v = from i in index
where i != p
select x[i];
r = v.ToArray<int>();
return r;
}
static void Search(int[] x) {
if (x.Length > 0) {
for (int i = 0 ; i < x.Length ; i++) {
SetCurrent(x,i);
Search(Get1(x,i));
}
}
}
}
}
//主要是Search递归会把数据搞乱,大家说怎么搞,本来,结果集应该是全排(阶乘)那么多个但这里却只有16个,这个
我也没搞清是怎么回事。
[解决办法]
帮顶~~~~
[解决办法]
我的vs是2005的,不支持linq,,,