那位大侠知道这个快速排序算法(C#)的错误啊,谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/21 09:10:47
using System;
using System.Collections.Generic;
using System.Collections;

namespace QuickSort
{
class Sort
{
static void Main(string[] args)
{
int[] arrlist;
arrlist = new int [] {9,6,3,5,10,20,5,3 };
int low = 0, high = arrlist.Length - 1;
int Qcount = 0;
arrlistsort(arrlist,low,high,Qcount);//对数组进行排序,注意数组为引用类型
for (int h = 0; h < arrlist.Length; h++)
{
Console.Write("{0}\t", arrlist[h]);
}
}

public static int arrlistsort(int[] arrlist ,int low,int high,int Qcount )
{
int T=arrlist[low];
int k = low;
int I=low,J=high;
int qcount = Qcount;
int middle;
while (I!= J)
{

static void qsort(int[] a, int left, int right)
{
int l, r, pivot, temp;
l = left;
r = right;
pivot = a[(l + r) / 2];
while (l < r)
{
while (a[l] < pivot) ++l;
while (a[r] > pivot) --r;
if (l >= r) break;
temp = a[l];
a[l] = a[r];
a[r] = temp;
if (a[l] != pivot) ++l;
if (a[r] != pivot) --r;
}
if (l == r) ++l;
if (left < r) qsort(a, left, l - 1);
if (l < right) qsort(a, r + 1, right);
}

internal void QuickSort(int left, int right)
{
do
{
int low = left;
int hi = right;
int median = Array.GetMedian(low, hi);
this.SwapIfGreaterWithItems(low, median);
this.SwapIfGreaterWithItems(low, hi);
this.SwapIfGreaterWithItems(median, hi);
object y = this.keys[median];
do
{
try<