快速排序算法c#
来源:互联网 发布:c sql查询语句怎么写 编辑:程序博客网 时间:2024/05/19 22:55
using System;
using System.Collections.Generic;
using System.Text;
namespace Sort
...{
class Program
...{
static void Main(string[] args)
...{
int[] array = ...{ 8,22,9,12,4,5,2,1,1};
QuickSort(array, 0, array.Length - 1);
for (int i = 0; i < array.Length; i++)
...{
Console.WriteLine(array[i]);
}
Console.Read();
}
//快速排序从大到小
private static void QuickSort(int[] sort, int start, int end)
...{
int i = start;
int j = end + 1;
int val = sort[i];
do
...{
do
...{
i++;
} while (sort[i] > val && i < end);
do
...{
j--;
} while (sort[j] < val && j > start);
if (i < j)
...{
int temp;
temp = sort[i]; sort[i] = sort[j]; sort[j] = temp;
}
} while (i < j);
sort[start] = sort[j]; sort[j] = val;
if (j > start + 1) QuickSort(sort, start, j - 1);
if (j < end - 1) QuickSort(sort, j + 1, end);
}
}
}
using System.Collections.Generic;
using System.Text;
namespace Sort
...{
class Program
...{
static void Main(string[] args)
...{
int[] array = ...{ 8,22,9,12,4,5,2,1,1};
QuickSort(array, 0, array.Length - 1);
for (int i = 0; i < array.Length; i++)
...{
Console.WriteLine(array[i]);
}
Console.Read();
}
//快速排序从大到小
private static void QuickSort(int[] sort, int start, int end)
...{
int i = start;
int j = end + 1;
int val = sort[i];
do
...{
do
...{
i++;
} while (sort[i] > val && i < end);
do
...{
j--;
} while (sort[j] < val && j > start);
if (i < j)
...{
int temp;
temp = sort[i]; sort[i] = sort[j]; sort[j] = temp;
}
} while (i < j);
sort[start] = sort[j]; sort[j] = val;
if (j > start + 1) QuickSort(sort, start, j - 1);
if (j < end - 1) QuickSort(sort, j + 1, end);
}
}
}
看c++的数据结构时,觉得它上面的例子不正确,用c#来验证一下
- C#算法 快速排序
- 快速排序算法c#
- C#快速排序算法
- C#快速排序算法
- 【算法】C#快速排序类
- 【算法】C#快速排序类
- C#实现快速排序算法
- C#快速排序算法实现
- 快速排序算法c#版
- C#算法-------(五)快速排序
- 快速排序算法-c#版
- c# 快速排序算法实现
- C#实现快速排序算法
- 【快速排序算法-C#实现】
- 【算法】C#快速排序类(转载)
- C#泛型快速排序算法
- 快速排序算法(C#实现)
- c#冒泡排序算法和快速排序算法
- 掌握 Ajax,第 5 部分
- Virtools
- 我的Maven2之旅:一.前言,准备及安装.
- 掌握 Ajax,第 6 部分
- 给别人的电脑创建一个删不掉的管理员
- 快速排序算法c#
- 好的 免费 报表控件 很多
- 解决Activex控件需要激活的问题
- 串口通讯基础
- 老生常谈:关于分页查询和性能问题
- 我的Maven2之旅:二.Maven常用命令
- Linux 下串口编程入门
- GetWindowLong函数(最好的解释资料,绝对值得一看,此函数在子类化技巧时候经常用到)
- sql — 题