高手帮忙看看这算法行不

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)
{ Console.ReadKey(); }*/ //弄了个无限循环,好玩!死也退不出...
Console.ReadKey();

}
}
}
...全文
42 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lzf616 2008-07-10
  • 打赏
  • 举报
回复
是问,这样写的算法的缺点是什么 。。。。有优点么?
我姓区不姓区 2008-07-10
  • 打赏
  • 举报
回复
你想问什么?

110,032

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧