快速排序第二种(易于理解的)
static void Main(string[] args)
{
ArrayList at=new ArrayList();
int[] number=new int[]{5679,4,36,67976,124,235,453,436,6589,0,5,6,346,457,34,3642};
foreach(int i in number)
{
at.Add(i);
}
ArrayList al=QuickSort(at);
foreach (int j in al)
{
Console.WriteLine(j);
}
Console.ReadKey();
}
static ArrayList QuickSort(ArrayList list)
{
if (list.Count <= 1) return list;
int middle = list.Count / 2;
int value=(int)list[middle];
list.RemoveAt(middle);
ArrayList left = new ArrayList();
ArrayList right = new ArrayList();
for (int i = 0; i < list.Count; i++)
{
if ((int)list[i] < value)
{
left.Add(list[i]);
}
else
{
right.Add(list[i]);
}
}
ArrayList newarray = QuickSort(left);
newarray.Add(value);
newarray.AddRange(QuickSort(right));
return newarray;
}