using System;
namespace ConsoleApp12
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
int[] aa = new int[] {3,12,8,7,4,3,89,1 };
QuickSort(aa, 0, aa.Length - 1);
}
public static void QuickSort(int[] list, int start, int end)
{
if(list==null || list.Length <= 1)
{
return ;
}
if (start >= end)
{
return;
}
int tmp = list[start];
int tmpStart = start;
int tmpEnd = end;
while (start < end)
{
while (start < end && tmp <= list[end])
{
end--;
}
if (start < end)
{
list[start] = list[end];
start++;
}
else
{
break;
}
while(start<end && tmp >= list[start])
{
start++;
}
if (start < end)
{
list[end] = list[start];
end--;
}
else
{
break;
}
}
list[start] = tmp;
QuickSort(list, tmpStart, start - 1);
QuickSort(list, start+1, tmpEnd);
}
}
}
快速排序C#代码
最新推荐文章于 2024-03-08 11:50:53 发布
681

被折叠的 条评论
为什么被折叠?



