// quitsort.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include
using namespace std;
int partition(int a[], int l, int h){
int key = a[l];
int low, high;
low = l; high = h;
while (low < high){
while (lowkey){
high--;
}
if (low < high){ a[low++] = a[high]; }
while (low < high&&a[low] < key){
low++;
}
if (low < high){ a[high--]=a[low]; }
}
a[low] = key;
return low;
}
void print(int a[], int length){
for (int i = 0; i < length; i++){
cout << a[i] << " ";
}
cout << endl;
}
void quitsort(int a[], int first, int last){
if (first < last){
int q = partition(a, first, last);
print(a, 10);
quitsort(a, first, q - 1);
quitsort(a, q + 1, last);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int a[] = {11,23,9,34,0,12,81,45,100,90};
quitsort(a, 0, 9);
return 0;
}
- 转载请注明来源:c++实现快速排序
- 本文永久链接地址:http://icehill.cn/post/single/info/76.html