#include <iostream>
using namespace std;
void swap(int *a,int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
int partition (int *arr, int low, int high)
{
int pivot = arr[high]; // pivot
int i = (low - 1); // Index of smaller element
for (int j = low; j <= high- 1; j++)
{
// If current element is smaller than or
// equal to pivot
if (arr[j] <= pivot)
{
// i++; // increment index of smaller element
swap(&arr[++i], &arr[j]);
}
}
swap(&arr[++i], &arr[high]);
return (i);
}
void recQuicksort(int *arr,int l,int h)
{
if(l<h)
{
int pivot = partition(arr,l,h);
recQuicksort(arr,l,pivot-1);
recQuicksort(arr,pivot+1,h);
}
}
int main() {
// your code goes here
int a[6] = {44, 33, 23, 22, 2, 1};
recQuicksort(a, 0, 5);
for (int i = 0; i < 6; i++) printf("%d ", a[i]);
printf("\n");
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBzd2FwKGludCAqYSxpbnQgKmIpCnsKICAgIGludCB0ZW1wID0gKmE7CiAgICAqYSA9ICpiOwogICAgKmIgPSB0ZW1wOwp9CgppbnQgcGFydGl0aW9uIChpbnQgKmFyciwgaW50IGxvdywgaW50IGhpZ2gpIAp7IAogICAgaW50IHBpdm90ID0gYXJyW2hpZ2hdOyAgICAvLyBwaXZvdCAKICAgIGludCBpID0gKGxvdyAtIDEpOyAgLy8gSW5kZXggb2Ygc21hbGxlciBlbGVtZW50IAoKICAgIGZvciAoaW50IGogPSBsb3c7IGogPD0gaGlnaC0gMTsgaisrKSAKICAgIHsgCiAgICAgICAgLy8gSWYgY3VycmVudCBlbGVtZW50IGlzIHNtYWxsZXIgdGhhbiBvciAKICAgICAgICAvLyBlcXVhbCB0byBwaXZvdCAKICAgICAgICBpZiAoYXJyW2pdIDw9IHBpdm90KSAKICAgICAgICB7IAogICAgICAgICAgICAvLyBpKys7ICAgIC8vIGluY3JlbWVudCBpbmRleCBvZiBzbWFsbGVyIGVsZW1lbnQgCiAgICAgICAgICAgIHN3YXAoJmFyclsrK2ldLCAmYXJyW2pdKTsgCiAgICAgICAgfSAKICAgIH0gCiAgICBzd2FwKCZhcnJbKytpXSwgJmFycltoaWdoXSk7IAogICAgcmV0dXJuIChpKTsgCn0gCnZvaWQgcmVjUXVpY2tzb3J0KGludCAqYXJyLGludCBsLGludCBoKQp7CiAgICBpZihsPGgpCiAgICB7CiAgICAgICAgaW50IHBpdm90ID0gIHBhcnRpdGlvbihhcnIsbCxoKTsKICAgICAgICByZWNRdWlja3NvcnQoYXJyLGwscGl2b3QtMSk7CiAgICAgICAgcmVjUXVpY2tzb3J0KGFycixwaXZvdCsxLGgpOwogICAgfQp9CmludCBtYWluKCkgewoJLy8geW91ciBjb2RlIGdvZXMgaGVyZQoJaW50IGFbNl0gPSB7NDQsIDMzLCAyMywgMjIsIDIsIDF9OwoJcmVjUXVpY2tzb3J0KGEsIDAsIDUpOwoJZm9yIChpbnQgaSA9IDA7IGkgPCA2OyBpKyspIHByaW50ZigiJWQgIiwgYVtpXSk7CglwcmludGYoIlxuIik7CglyZXR1cm4gMDsKfQ==