日期:2014-05-17 浏览次数:20676 次
public static ArrayList digitalReorganization(string number)//不一定要是number
{
int length = number.Length;
Array distinct = number.ToArray().Distinct().ToArray();
string mode = "part1";
if (length != distinct.Length) mode = "part2"; //2种方法,重复的话可以使用第2种
ArrayList result = new ArrayList();
result.Add(number);
for (int i = 0; i < number.Length - 1; i++)
{
if (mode == "part1") result = digitalReorganizationSort(result, i);
else result = digitalReorganizationSortPart2(result, i);
}
if (mode == "part1") result = new ArrayList(result.ToArray().Distinct().ToArray()); //需要过滤掉重复的
return result;
}
public static ArrayList digitalReorganizationSort(ArrayList numberlist, int index)
{
int loop_count = numberlist.Count;
for (var i = 0; i < loop_count; i++)
{
ArrayList old = new ArrayList(numberlist[i].ToString().ToArray());
for (var j = 0; j < old.Count - 1 - index; j++)
{
ArrayList temp = new ArrayList(numberlist[i].ToString().ToArray()); //每次copy一个来对调位置
string word = old[index].ToString();
string next = old[index + j + 1].ToString();
&nbs