【面试准备】快排

来源:互联网 发布:淘宝白色长连衣裙 编辑:程序博客网 时间:2024/05/16 18:28
#include <iostream>using namespace std;void Quicksort(int e[],int first,int end){int i = first, j = end;int temp = e[i];while(i<j){while(i<j && temp<=e[j]){j--;}e[i] = e[j];while(i<j && e[i]<= temp){i++;}e[j] = e[i];}e[i] = temp;if(first<i-1){Quicksort(e,first,i-1);}if(end>i+1){Quicksort(e,i+1,end);}}int main() {int a[10]={1,4,32,12,3,4,2,7,5,7};Quicksort(a,0,9);for(int i = 0; i <10 ;++i){cout<<a[i]<<" ";}cout<<endl;return 0;}

0 0
原创粉丝点击