//Code for Quicksort using recursion
#include<bits/stdc++.h>
using namespace std;
int partition(int *arr,int s,int e){
int pivot = arr[s];
int pivotIndex,cnt=0;
for(int i=s+1;i<=e;i++){
if(arr[i]<=pivot){
cnt++;
}
}
pivotIndex = s + cnt;
swap(arr[s],arr[pivotIndex]);
int i=s,j=e;
while(pivotIndex>i && pivotIndex < j){
while(arr[i]<=pivot){
i++;
}
while(arr[j]>pivot){
j--;
}
if(pivotIndex>i && pivotIndex < j){
swap(arr[i++],arr[j--]);
}
}
return pivotIndex;
}
void quicksort(int *arr,int s, int e){
if(s>=e){
return;
}
int p = partition(arr,s,e);
quicksort(arr,s,p-1);
quicksort(arr,p+1,e);
}
int main(){
int arr[]={ 50,70,60,12,23,55,33};
int n=7;
quicksort(arr,0,n-1);
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
}
Ly9Db2RlIGZvciBRdWlja3NvcnQgdXNpbmcgcmVjdXJzaW9uCiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgcGFydGl0aW9uKGludCAqYXJyLGludCBzLGludCBlKXsKCWludCBwaXZvdCA9IGFycltzXTsKCWludCBwaXZvdEluZGV4LGNudD0wOwoJZm9yKGludCBpPXMrMTtpPD1lO2krKyl7CgkJaWYoYXJyW2ldPD1waXZvdCl7CgkJCWNudCsrOwoJCX0KCX0KCXBpdm90SW5kZXggPSBzICsgY250OwoJc3dhcChhcnJbc10sYXJyW3Bpdm90SW5kZXhdKTsKCglpbnQgaT1zLGo9ZTsKCXdoaWxlKHBpdm90SW5kZXg+aSAmJiBwaXZvdEluZGV4IDwgail7CgkJd2hpbGUoYXJyW2ldPD1waXZvdCl7CgkJCWkrKzsKCQl9CgkJd2hpbGUoYXJyW2pdPnBpdm90KXsKCQkJai0tOwoJCX0KCQlpZihwaXZvdEluZGV4PmkgJiYgcGl2b3RJbmRleCA8IGopewoJCQlzd2FwKGFycltpKytdLGFycltqLS1dKTsKCQ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