c# 快速排序求解答,该如何解决
c# 快速排序求解答
写了个快速排序的方法,感觉逻辑上没有错误,但是运行结果不对,好像递归那里没起作用,但是我设置了断点发现递归那里执行了好多遍的,不知道错在哪里了,求高人指点,谢谢!
运行结果是:2,4,5,7,6
写了个快速排序的方法,感觉逻辑上没有错误,但是运行结果不对,好像递归那里没起作用,但是我设置了断点发现递归那里执行了好多遍的,不知道错在哪里了,求高人指点,谢谢!
运行结果是:2,4,5,7,6
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)