下载此文档

c#快速排序算法.doc


文档分类:IT计算机 | 页数:约2页 举报非法文档有奖
1/2
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/2 下载此文档
文档列表 文档介绍
//快速排序的具体过程如下:
//1:在待排序的n个记录中,任取一个作为基准,把数组分为两部分,第一组的排序码都小于或等于该排序码,第二组的排序码,都大于或等于该排序码,并把该基准放在两组中间。
2:采用同样的方法分别对左右两组进行排序//快速排序的具体过程如下:
//1:在待排序的n个记录中,任取一个作为基准,把数组分为两部分,第一组的排序码都小于或等于该排序码,第二组的排序码,都大于或等于该排序码,并把该基准放在两组中间。
2:采用同样的方法分别对左右两组进行排序,直到所有的记录都排到适当的位置。
///快速递归排序
privatestaticvoid QuickSort(int[] R, int low, int high)
{
int pivotLoc = 0;
if (low < high)
{
pivotLoc = Partition(R, low, high);
QuickSort(R, low, pivotLoc - 1);
QuickSort(R, pivotLoc + 1, high);
}
}
privatestaticint Partition(int[] R, int low, int high)
{
int temp = R[low];
while (low < high)
{
if (low < high && temp <= R[high])
{
high--;
}
R[low] = R[high];
if (low < high && R[low] <= temp)
{
low++;
}
R[high] = R[low];
}
R[low] = temp;
return low;
}
//快速非递归排序
publicstaticvoid QuickSort(int [] R,int Low,int High,Stack<int> stack)
{
int low = Low;
int high = High;
int temp = R[low];
while (high > low)
{
while (low < high && temp <= R[high])
{
high--;
}
if (high > low)
{
R[low] = R[hi

c#快速排序算法 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数2
  • 收藏数0 收藏
  • 顶次数0
  • 上传人taoapp
  • 文件大小16 KB
  • 时间2022-04-17
最近更新