首页 > 其他 > 详细

哪里错了

时间:2015-03-24 20:58:47      阅读:126      评论:0      收藏:0      [点我收藏+]

#include<iostream>
using namespace std;
//第一次找到轴值
int one(int a[],int first,int end){
int i,j,temp;
i=first;
j=end;
while(i==j){ //相等的时候即找到
while(i<j&&a[i]<a[j]) i++; //先从左边走
if(i<j){temp=a[i];a[i]=a[j];a[j]=temp;} //左边大则交换
while(i<j&&a[i]<a[j]) j--; //再从右边走
if(i<j){temp=a[i];a[i]=a[j];a[j]=temp;} //右边小交换
}
return i; //跳出说明找到了
}
//快速排序递归
void quicksort(int a[],int first,int end){
int position;
if(first<end){
position=one(a,first,end);
quicksort(a,first,position-1);
quicksort(a,position+1,end);
}
}
int main(){
int i,a[5]={3,4,1,2,5};
quicksort(a,0,4);
for(i=0;i<5;i++){
cout<<a[i]<<‘ ‘;
}
cout<<endl;
return 0;
}

哪里错了

原文:http://www.cnblogs.com/apple-apple-apple/p/4363923.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!