快速排序 c++代码
来源:互联网 发布:丝路英雄嘉峪关数据 编辑:程序博客网 时间:2024/06/07 00:25
#include <iostream>
using namespace std;
int partition(int *l,int low,int high){
while(low<high){
while(low<high&&l[high]>=l[low]){
high--;
}
swap(l[low],l[high]);
while(low<high&&l[low]<=l[high]){
low++;
}
swap(l[low],l[high]);
}
return low;
}
void qkSort(int *l,int low,int high){
if(low<high){
int p=partition(l,low,high);
qkSort(l,low,p-1);
qkSort(l,p+1,high);
}
}
const int maxn=1000;
int a[maxn];
int main()
{
int n;
while(cin>>n){
for(int i=0;i<n;i++)scanf("%d",&a[i]);
qkSort(a,0,n-1);
for(int i=0;i<n;i++)
printf("%d ",a[i]);
}
return 0;
}
using namespace std;
int partition(int *l,int low,int high){
while(low<high){
while(low<high&&l[high]>=l[low]){
high--;
}
swap(l[low],l[high]);
while(low<high&&l[low]<=l[high]){
low++;
}
swap(l[low],l[high]);
}
return low;
}
void qkSort(int *l,int low,int high){
if(low<high){
int p=partition(l,low,high);
qkSort(l,low,p-1);
qkSort(l,p+1,high);
}
}
const int maxn=1000;
int a[maxn];
int main()
{
int n;
while(cin>>n){
for(int i=0;i<n;i++)scanf("%d",&a[i]);
qkSort(a,0,n-1);
for(int i=0;i<n;i++)
printf("%d ",a[i]);
}
return 0;
}
0 0
- 快速排序 C代码
- c代码--快速排序问题
- c代码--快速排序问题
- 快速排序C语言代码
- c语言快速排序代码
- Objective-C 快速排序代码
- 【排序】 快速排序代码-C语言版
- 快速排序的C语言代码实现
- 快速排序的C语言代码实现
- 快速排序的C语言代码实现
- 快速排序 qsort c语言代码
- 快速排序的C语言代码实现
- 快速排序算法C,JAVA代码
- C语言快速排序算法代码分析
- 编程算法 - 快速排序算法 代码(C)
- C语言快速排序算法及代码
- 优化快速排序 C语言代码
- 快速排序的c语言实现代码
- 25.2.4 USB驱动程序框架
- 【数论】 HDOJ 4986 Little Pony and Alohomora Part I
- oracle initialization or shutdown in progress 问题解决
- RabbitMQ学习(三).NET Client之Publish/Subscribe
- static成员变量定义初始化
- 快速排序 c++代码
- 公司新阵列RAID5的配置
- 应用程序开发总结(8)--自定义序列化类
- 【强连通分量】 HDOJ 4985 Little Pony and Permutation
- 类模板
- centos系统yum安装apache+php+mysql
- 八种主流NoSQL数据库对比
- 采用新花生壳,进行内网端口映射
- android的退出程序的几种方法