快速排序
2016-07-20 17:09
183 查看
<pre name="code" class="cpp">#include<iostream> using namespace std; void swap(int &a,int &b) { int t=a; a=b; b=t; } void quick_sort(int a[],int low,int high) { int i,j,temp; temp=a[low]; i=low; j=high; while(i<j) { while(i<j) { while(i<j&&a[j]>temp) j--; while(i<j&&a[i]<=temp) i++; swap(a[i],a[j]); } swap(a[low],a[j]); quick_sort(a,low,i-1); quick_sort(a,i+1,high); } } int main() { int a[]={6,1,2,7,9,3,4,5,10,8}; quick_sort(a,0,9); for(int i=0;i<10;i++) { cout<<a[i]; } return 0; }
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- 在命令行用 sort 进行排序
- 关于指针的一些事情
- 快速排序
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- 书评:《算法之美( Algorithms to Live By )》
- 动易2006序列号破解算法公布
- 文件遍历排序函数
- C#数据结构之顺序表(SeqList)实例详解
- 关于C#中排序函数的总结
- C#递归算法之分而治之策略
- C#选择排序法实例分析
- Ruby实现的矩阵连乘算法
- C#插入法排序算法实例分析
- C#算法之大牛生小牛的问题高效解决方法
- Lua中调用C++函数示例
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(七):数据结构详解