#include <iostream>
using namespace std;
int quick(int a[], int first, int last) {
if (first < last)
{
int i = first+1;
int j = last;
int pivot = first;
int temp;
while (i <= j)
{
while (a[i] <= a[pivot] ) {
i++;
}
while (a[j] > a[pivot] ) {
j--;
}
if(i<=j)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
temp = a[pivot];
a[pivot] = a[j];
a[j] = temp;
quick(a, first, j - 1);
quick(a, j + 1, last);
}
return 0;
}
int main()
{
int a[] = {2, 7, 4, 3, 5, 8};
int n = 6;
quick(a, 0, n - 1);
cout << "Sorted array: ";
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: