【排序】快速排序
来源:互联网 发布:小白素材vip源码 编辑:程序博客网 时间:2024/04/30 11:37
#include<iostream>using namespace std;int pnumsrtition(int nums[], int low, int high){ int pivot_key = nums[low];//用区间的第1个记录作为基准 while (low < high){//从区间两端交替向中间扫描,直到low=high为止 while (low < high&&nums[high] >= pivot_key) high--;//从右向左扫描,查到第1个关键字小于pivot_key的记录nums[hgih] if (low < high) nums[low++] = nums[high];//相当于交换nums[low]和nums[high] while (low < high&&nums[low] <= pivot_key) low++; if (low < high) nums[high--] = nums[low]; } nums[low] = pivot_key;//基准记录已被最后定位 return low;}void quick_sort(int nums[], int low, int high){ int pivot; //划分后的基准记录的位置 if (low < high){ pivot = pnumsrtition(nums, low, high);//做划分 quick_sort(nums, low, pivot - 1); quick_sort(nums, pivot + 1, high); }}void print_numsrrnumsy(int nums[], int len){ for (int i = 0; i < len; i++) cout << nums[i] << ' '; cout << endl;}int main(){ int nums[] = { 9, 1, 5, 8, 3, 7, 4, 6, 2 }; int len = sizeof(nums) / sizeof(int); quick_sort(nums, 0, len - 1); print_numsrrnumsy(nums, len); return 0;}
0 0
- 排序之快速排序
- 排序算法--快速排序
- 插入排序,快速排序
- 快速排序 冒泡排序
- 排序算法--快速排序
- 排序之 快速排序
- 排序之快速排序
- 快速排序、冒泡排序
- 排序---快速排序
- 排序4快速排序
- 【排序】快速排序
- 排序算法---快速排序
- 快速排序,选择排序
- 排序算法-快速排序
- 【排序】快速排序
- 【基础排序】快速排序
- 排序之------快速排序
- 排序–快速排序
- 打印沙漏
- proc文件系统的理解
- Android中Service和IntentService使用区别
- HDU 4417 主席树
- 笔记本adb无线调试最简便的方法
- 【排序】快速排序
- VS2008中关于“MessageBoxW”: 不能将参数 2 从“char [20]”转换为“LPCWSTR”的错误解决
- 安装完最小化 RHEL/CentOS 7 后需要做的 30 件事情(一)
- ClassNotFoundException: org.apache.ws.commons.schema.resolver.URIResolver
- 删除jar包的某些class重新打jar包
- 常用控件的初始化
- ContentProvider基础
- C/C++ 关于大小端模式
- UVA1594