快速排序
来源:互联网 发布:淘宝互刷微信群 编辑:程序博客网 时间:2024/06/05 20:21
#include <cstdio>#include <cstring>#include <vector>#include <algorithm>#include <iostream>using namespace std;typedef struct{ int key;}Data;typedef struct { Data *data; int length;}Sqlist;void input(Sqlist &L){ int n; cout<<"please enter a number"<<endl; cin>>n; L.length=n; L.data=(Data *)malloc(sizeof(int)*(L.length+1)); for(int i=1;i<=n;i++){ cout<<i<<" number : "; cin>>L.data[i].key; }}int Pation(Sqlist &L,int low,int high){ L.data[0]=L.data[low]; int pivotkey=L.data[low].key; while(low<high){ while(low<high&&L.data[high].key>=pivotkey) --high; L.data[low]=L.data[high]; while(low<high&&L.data[low].key<=pivotkey) ++low; L.data[high]=L.data[low]; } L.data[low]=L.data[0]; return low;}void Qsort(Sqlist &L,int low,int high){ if(low>high) return ; if(low<high){ int pivoloc=Pation(L,low,high); cout<<"pivoloc "<<pivoloc<<endl; Qsort(L,low,pivoloc-1); Qsort(L,pivoloc+1,high); }}//Qsortvoid print(Sqlist &L){ for(int i=1;i<=L.length;i++){ cout<<i<<" "<<L.data[i].key<<endl; } }int main(){ Sqlist L; input(L); print(L); Qsort(L,1,L.length); print(L);}
0 0
- 快速排序
- 快速排序
- 快速排序
- 快速排序!
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 文档重点
- CentOS 下搭建Web服务器
- 罗升阳:那两年炼就的Android内功修养
- PC 与 Android 的adb同步通信(一)
- Canvas 与 SVG
- 快速排序
- 黑马程序员_IO(以字节为导向的 stream------InputStream)
- Chrome 浏览器加载 css Failed to load resource
- 第十二章:12.3 源码包服务的管理
- 【android】关于如何惟一地标识一台Android设备的总结性讨论
- Myeclipse8.5中svn插件安装不上去
- 古代饮食习惯来源
- ContentProvider
- libjpeg编译windows