#include<iostream> using namespace std; int Partition(int *a, int p, int r) { int i = p - 1; int x = a[r]; for (int j = p; j < r; j++) { if (a[j] < x) { i++; swap(a[i],a[j]); } } swap(a[i+1], a[r]); return (i + 1); } void QuickSort(int *A, int p, int r) { if (p < r) { int q = Partition(A,p,r); QuickSort(A,p, q - 1); QuickSort(A,q+1,r); } } int main() { int A[] = {2,8,7,1,3,5,6,4}; int N = sizeof A / sizeof A[0]; QuickSort(A, 0, N-1); for (int i = 0; i < N; i++) cout << A[i] << " "; cout << " "; return 0; }