快速排序算法
来源:互联网 发布:免费普通话测试软件 编辑:程序博客网 时间:2024/06/05 19:30
#include <iostream>
using namespace std;
void Qsort(int a[],int low,int high)
{
if(low>=high)
{
return;
}
int first=low;
int last=high;
int key=a[first];
while(first<last)
{
while(first<last && a[last]>=key ) --last;
a[first] =a[last];
while(first<last && a[first]<=key) ++first;
a[last]=a[first];
}
a[first]=key;
Qsort(a,low,first-1);
Qsort(a,last+1,high);
}
int main()
{
int a[]={57,68,59,52,72,28,96,33,24};
Qsort(a,0,sizeof(a)/sizeof(a[0]));
for(int i=0;i<sizeof(a)/sizeof(a[0]);i++)
{
cout<<a[i]<<" ";
}
return 0;
using namespace std;
void Qsort(int a[],int low,int high)
{
if(low>=high)
{
return;
}
int first=low;
int last=high;
int key=a[first];
while(first<last)
{
while(first<last && a[last]>=key ) --last;
a[first] =a[last];
while(first<last && a[first]<=key) ++first;
a[last]=a[first];
}
a[first]=key;
Qsort(a,low,first-1);
Qsort(a,last+1,high);
}
int main()
{
int a[]={57,68,59,52,72,28,96,33,24};
Qsort(a,0,sizeof(a)/sizeof(a[0]));
for(int i=0;i<sizeof(a)/sizeof(a[0]);i++)
{
cout<<a[i]<<" ";
}
return 0;
}
//参考数据结构(严蔚敏,清华大学)p274
0 0
- 排序算法--快速排序
- 排序算法--快速排序
- 排序算法---快速排序
- 排序算法-快速排序
- 排序算法------快速排序
- 排序算法---快速排序
- 排序算法-快速排序
- 排序算法---快速排序
- 排序算法--快速排序
- 排序算法--快速排序
- 排序算法--快速排序
- 排序算法:快速排序
- 排序算法 快速排序
- 排序算法--快速排序
- 排序算法--快速排序
- 【排序算法】快速排序
- 排序算法--快速排序
- 排序算法:快速排序
- linux(ubuntu12.04)下手机真机调试eclipse上的android程序
- Excel 小写金额转大写
- PHP jQuery ajax 表单提交小示例(含insert, select)
- android Button 源码
- Function() 不是 function()
- 快速排序算法
- tomcat配置文件server.xml详解
- Java:多线程模拟多站点售票过程
- oracle基本管理(1)
- fuser 命令
- Oracle 取消登陆与登出审计
- asm上的备份怎么在另一台机器上恢复
- android View 源码
- 微信不弹出授权页面获取用户详细信息