快速排序
来源:互联网 发布:编程思路怎么写 编辑:程序博客网 时间:2024/05/17 23:35
快速排序算法
百科名片
。
#include <iostream>#include <algorithm>using namespace std;const int size = 1000;//第一种写法 int partition1(int a[], int low, int high){ int p = a[low]; while (low < high) { while (low < high && p <= a[high]) high--;//右边的与p比较,若右边的大于它继续往左走 a[low] = a[high];//遇到a[low] > a[high]了,while结束,交换p和a[high]; while (low < high && a[low] <= p) low++; a[high] = a[low]; } a[low] = p; return low;}//第2种写法 int partition2(int a[], int low, int high){ //选择第一个a[low]作为划分的临界值 while (low < high) { while (low < high && a[low] <= a[high]) high--; swap(a[low], a[high]); while (low < high && a[low] <= a[high]) low++; swap(a[low], a[high]); } return low;} void Qsort(int a[], int low, int high){ if (low > high) return; int p = partition2(a, low, high); Qsort(a, low, p-1); Qsort(a, p+1, high);}int main(){ int N, arr[size]; int i; while (cin >> N) { for (i = 0; i < N; ++i) cin >> arr[i]; Qsort(arr, 0, N-1); for (i = 0; i < N-1; ++i) cout << arr[i] << " "; cout << arr[i] << endl; } return 0;}
快排题目 : hdu 1157 4022 二分+快排 1040 1425 1106
2037 贪心结构体快排
- 快速排序
- 快速排序
- 快速排序
- 快速排序!
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- Eclipse出现adb连接不上的问题
- excel与oracle中字符串长度
- +++++Understanding oracle IOPS and Throughput
- Android 判断网络连接运用
- Android 在程序中禁止屏幕旋转和重启Activity
- 快速排序
- windows下apache tomcat整合
- memccpy() -- 拷贝内存内容
- Android学习--动态向SPinner控件中添加数据
- 源代码制作成RPM包
- 双向链表的相关操作C++实现
- VC往PE文件末尾读写数据
- 潮人必备:极简风格的iPhone外设Spike
- 为鼠标点击事件添加全局效果处理