#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int n1;
class quick
{
public:
int pass=0;
void quicksort(int a[],int left,int right)
{
int pivot,i,j,temp;
if(left<right)
{
pass++;
i=left;
j=right+1;
pivot = a[left];
cout<<"\n\t "<<pass<<" \t "<<pivot<<" \t
"<<left<<" \t "<<right<<" \t ";
while(i<j)
{
do i++; while(a[i]<pivot);
do j--; while(a[j]>pivot);
if(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
temp=a[left];
a[left]=a[j];
a[j]=temp;
for(i=1;i<=n1;i++)
cout<<" "<<a[i];
quicksort(a,left,j-1);
quicksort(a,j+1,right);
}
}
};
int main()
{
quick obj;
int n,i,a[20];
cout<<"\n\t Quick Sort";
cout<<"\n\t __________";
cout<<"\n\t Enter the no. of elements: ";
cin>>n;
n1=n;
cout<<"\n\t Enter the Array Elements: ";
for(i=1;i<=n;i++)
{
cout<<"\n\t";
cin>>a[i];
}
cout<<"\n\t Number of Elements : "<<n;
cout<<"\n\n\t Unsorted Data : ";
for(i=1;i<=n;i++)
cout<<a[i]<<"\t";
cout<<"\n";
cout<<"\n\t
_________________________________________________________________";
cout<<"\n\t Pass \t Pivot \t Left \t Right \t\t Elements ";
cout<<"\n\t
_________________________________________________________________";
[Link](a,1,n);
cout<<"\n\n\t Sorted Data : ";
for(i=1;i<=n;i++)
{
cout<<a[i]<<"\t";
}
return 0;
}