高手帮忙看看这算法行不
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();
}
}
}