快速排序算法c#版
来源:互联网 发布:韩顺平mysql视频 云盘 编辑:程序博客网 时间:2024/05/07 15:55
using System;
using System.Collections.Generic;
namespace QuickSort
{
class Sort
{
static void Main(string[] args)
{
List<int> list=new List<int>();
Console.WriteLine("快速排序法之后支点降序算法");
int[] arr = new int[] { 55, 6, 4, 7, 22, 59, 859, 2, 3, 35, 65 };
list.AddRange(arr);
QuickSortDescend(list, 0, list.Count - 1);
foreach (int i in list)
{
Console.WriteLine(i.ToString());
}
Console.ReadLine();
}
//快速排序算法前支点升序算法
public static void QuickSortAscend(List<int> list, int low, int high)
{
if (high > low)
{
int idxPartition = QuickSortAscendPartition(list, low, high);
QuickSortAscend(list, low, idxPartition - 1);
QuickSortAscend(list, idxPartition + 1, high);
}
}
private static int QuickSortAscendPartition(List<int> list, int low, int high)
{
int pivot = list[low]; //支点位置处的值
while (low < high)
{
//后边向前比较
while (low < high && list[high] <= pivot)
{
high--;
}
//检查位置
if (low != high)
{
list[low] = list[high]; //H处位置值较小,覆盖L处
low++;
}
//继续比较,L向右
while (low < high && list[low] >= pivot)
{
low++;
}
//检查位置
if (low != high)
{
list[high] = list[low];
high--;
}
}
list[low] = pivot;
return low;
}
//快速排序法之后支点降序算法
public static void QuickSortDescend(List<int> list, int left, int right)
{
if ( right> left)
{
int idxPartition = QuickSortDescendPartition(list, left, right);
QuickSortDescend(list, left, idxPartition - 1);
QuickSortDescend(list, idxPartition + 1, right);
}
}
private static int QuickSortDescendPartition(List<int> list, int left, int right)
{
int pivot = list[right];
while (left < right)
{
while (left < right && list[left] >= pivot)
{
left++;
}
if (left != right)
{
list[right] = list[left];
right--;
}
while (left < right && list[right] <= pivot)
{
right--;
}
if (left != right)
{
list[left] = list[right];
left++;
}
}
list[left] = pivot;
return left;
}
}
}
- 快速排序算法c#版
- 快速排序算法-c#版
- C#算法 快速排序
- 快速排序算法c#
- C#快速排序算法
- C#快速排序算法
- 【算法】C#快速排序类
- 【算法】C#快速排序类
- C#实现快速排序算法
- C#快速排序算法实现
- C#算法-------(五)快速排序
- c# 快速排序算法实现
- C#实现快速排序算法
- 【快速排序算法-C#实现】
- C#版快速排序
- 快速排序算法 c#版(递归实现)
- 【算法】C#快速排序类(转载)
- C#泛型快速排序算法
- 字符集问题的初步探讨(五)-导出文件字符集
- 中文表名-导入导出-字符集
- 小技巧给网页减肥 让网站访问提速
- struts2展现
- BULK INSERT 用法小实例。
- 快速排序算法c#版
- 随即产生1-100操作数的方法,产生一百个,每次都不相同,.NET, C#
- 如何测试程序的执行时间
- 简述C和C++的学习历程
- ACL总结(有时间写自反访问控制列表)
- 感悟设计模式
- Ajax的post方法的使用
- 在困难面前……
- 移植mplayer到mini2440的全过程