2019-05-23快速排序实现

#include

using namespace std;

#include

int Paration(int r[], int low, int high)

{

int i = low, j = high, pivot = r[low];

while (i < j)

{

while (ipivot)j--;

if (i < j)

{

swap(r[i++], r[j]);

}

while (i < j&&r[i] <= pivot)i++;

if (i < j)

{

swap(r[i], r[j--]);

}

}

return i;

}

void QuickSort(int R[], int low, int high)

{

int mid;

if (low < high)

{

mid = Paration(R, low, high);

QuickSort(R, low, mid - 1);

QuickSort(R, mid + 1, high);

}

}

int main()

{

int a[1000];

int i, N;

cout << "输入个数" << endl;

cin >> N;

for (i = 0; i < N; i++)

{

cin >> a[i];

}

QuickSort(a, 0, N - 1);

cout << "排序后" << endl;

for (i = 0; i < N; i++)

{

cout << a[i]<< endl;

}

cin >>a[1];

}

你可能感兴趣的:(2019-05-23快速排序实现)