日期:2014-05-17 浏览次数:20841 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace 快速排序
{
class Program
{
static void Main(string[] args)
{
//新建一个数组
int[] abc = new int[] { 5,7,6,2,4 };
ArrayList arrlist = new ArrayList();
//把数组添加到ArrayList中
arrlist.AddRange(abc);
Console.WriteLine("排序前:");
//循环打印出每个元素
foreach (int a in arrlist)
{
Console.Write("{0},", a);
}
//调用快速排序方法
arrlist=QuickSort(arrlist);
Console.WriteLine("排序后:");
foreach (int a in arrlist)
{
Console.Write("{0},", a);
}
Console.ReadKey();
}
public static ArrayList QuickSort(ArrayList arr)
{
//只要集合里面元素个数大于1,就一直进行分开操作
if (arr.Count > 1)