快速排序
来源:互联网 发布:手机淘宝怎么降价通知 编辑:程序博客网 时间:2024/05/21 23:33
#include<iostream>using namespace std;int a[100];int n;int partition(int r[],int low,int high)// 这只是一次划分,还要进行递归排序。 { r[0] = r[low]; int pivotkey = r[low]; while(low < high) { while(low < high && r[high] >= pivotkey) --high; if(low < high) r[low++] = r[high]; while(low < high && r[low] <= pivotkey) ++low; if(low < high) r[high--] = r[low]; } r[low] = r[0]; return low;}void Qsort(int r[],int s,int t){if(s<t){int pivotloc = partition(r,s,t);Qsort(r,s,pivotloc-1);Qsort(r,pivotloc+1,t);}}int main(){while(cin>>n){for(int i = 1; i <= n; i ++)cin>>a[i];Qsort(a,1,n); for(int i = 1; i <= n; i ++) cout<<a[i]<<" "; cout<<endl;}return 0;}
0 0
- 快速排序
- 快速排序
- 快速排序
- 快速排序!
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- HDU2032
- 哈夫曼树(最优二叉树)的创建
- 【图论】【启发式搜索】[POJ 2449]Remmarguts' Date
- LeetCode(48) Rotate Image
- 欢迎使用CSDN-markdown编辑器
- 快速排序
- SharePoint 2013 --Spquery执行报错
- 【小明渗透日记】小明要租房
- NYOJ--24素数距离问题
- 服务器返回代码
- 初识python django, 让我们一起进入python的世界吧
- 微信公众号用户与网站用户的绑定方案
- 缓存 LruCache 使用
- Rails 上传图片