排序算法:快速排序
来源:互联网 发布:淘宝未18购买虚拟物品 编辑:程序博客网 时间:2024/05/17 19:57
快速排序和冒泡排序成为交换排序:
1.找到一个值:然后把比他大的放到一边,比他小或者相等的放到一边;
2.利用分治法再分别对比他大的子说组和比他小的子数组分别排序,依次低轨到最后没元素。
空间复杂度:O()
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication5{ class Program { static void Main(string[] args) { int[] s=new int[]{108, 332, 2,3,5,5,8,1,18,7}; QuickSort q = new QuickSort(); q.QuickSortMethod(s, 0, s.Length - 1); foreach(int e in s) Console.WriteLine(e); } public class QuickSort { public void QuickSortMethod(int[] list, int start, int end) { if (list == null || list.Length <= 0) return; int s=start; int e=end; if (s >= e) { return; } int temp = list[s]; while(s<e) { while(temp<=list[e] && s<e) { e--; } if(s==e) { break; } list[s] = list[e]; s++; while(temp>list[s] && s<e) { s++; } if(s==e) { break; } list[e] = list[s]; } list[s] = temp; QuickSortMethod(list, start, s - 1); QuickSortMethod(list, s + 1, end); } } }}
0 0
- 排序算法--快速排序
- 排序算法--快速排序
- 排序算法---快速排序
- 排序算法-快速排序
- 排序算法------快速排序
- 排序算法---快速排序
- 排序算法-快速排序
- 排序算法---快速排序
- 排序算法--快速排序
- 排序算法--快速排序
- 排序算法--快速排序
- 排序算法:快速排序
- 排序算法 快速排序
- 排序算法--快速排序
- 排序算法--快速排序
- 【排序算法】快速排序
- 排序算法--快速排序
- 排序算法:快速排序
- GraphicsMagick安装与IMG4图片压缩
- 【iOS】数据库FMDB的使用(二)
- js 无缝滚动
- 选项切换条--第三方开源--SHSegmentControl
- CheungSSH国产自动化运维工具开源Web界面
- 排序算法:快速排序
- qt中qmake与ros结合
- 用adb操作android
- 虚幻4 捏脸和换装系统实现
- sqlplus安装配置
- TabControl添加关闭按钮
- CString与char * ,string的互相转换
- json 在java 中的应用
- Java 带参数构造函数