快速排序

来源:互联网 发布:大学生网络诈骗感悟 编辑:程序博客网 时间:2024/05/18 01:07
//============================================================================
// Name        : C++Study.cpp
// Author      : pan
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================


#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <assert.h>
#include <string.h>
using namespace std;


int partion(int a[], int start, int end) {
int temp = a[start];
while (start < end) {
while (a[end] > temp && start < end)
end--;
a[start] = a[end];
while (a[start] < temp & start < end)
start++;
a[end] = a[start];
}
a[start] = temp;
return start;
}




void quick_sort(int a[],int start,int end)
{
    if(start<end)
    {
    int k=partion(a,start,end);
    quick_sort(a,start,k-1);
    quick_sort(a,k+1,end);


    }


}
int main() {


int a[10]={1,3,2,4,6,5,7,10,9,8};
quick_sort(a,0,9);


for (int i = 0; i < 10; ++i) {
cout<<a[i];
}
return 0;
}
0 0