高手帮忙看看这算法行不

lzf616 2008-07-10 10:43:19
using System;
using System.Collections.Generic;
using System.Text;

namespace Relay
{
class maxNUM
{ public int maxN( int a, int b)
{
if (a > b)
{
return a;
}
else
{
return b;
}
}
}
}

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Relay
{
class maxMNUM
{

maxNUM p = new maxNUM();

public int maxMN(int[] n)
{
int[] t =new int[n.Length];
int c = n.Length;
if (c == 1)
{
return n[0];
}
else if (c == 2)
{

return p.maxN(n[0], n[1]);

}
else
{

t[c-1] = n[c - 1];
ArrayList al = new ArrayList(n);
al.RemoveAt(c - 1);
n = (int[])al.ToArray(typeof(int));
c = c - 1;
return p.maxN(maxMN(n), t[c]);

}
}
}
}

using System;
using System.Collections;
using System.Text;

namespace Relay
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[] { 1, 3, 9, 7, 21, 8, 4, 5, 11, 78 };
int pn = arr.Length;
int[] newArr=new int[pn];
ArrayList al = new ArrayList(arr);

maxMNUM max = new maxMNUM();
for (int i = pn-1; i>=0; i--)
{
newArr[i] = max.maxMN(arr);
al.Remove(newArr[i]);
arr = (int[])al.ToArray(typeof(int));
}
for (int j = 0;j<pn ;j++ )
{
Console.WriteLine(newArr[j]);
}
/* while (true)

}
}
}
...全文
44 2 打赏 收藏 转发到动态 举报

2 条回复

lzf616 2008-07-10
• 打赏
• 举报

• 打赏
• 举报

110,891

• 近7日
• 近30日
• 至今