#include <iostream>
using namespace std;
int quickSort(int a[],int l,int r);
int main()
{
int n,data,a[100];
cout<<"Enter no. of values: ";
cin>>n;
cout<<"Enter "<<n<<" values : ";
for(int x=0;x<n;x++) {
cin>>a[x];
}
quickSort(a,0,n);
cout<<"Array after Sorting using Quick Sort: \n";
for(int x=0;x<n;x++) {
cout<<a[x]<<"\n";
}
return(0);
}
int quickSort(int a[],int l,int r)
{
int temp;
if(r-l<=1) {
return(0);
}
int y=l+1;
for(int g=l+1;g<r;g++) {
if(a[g]<=a[l]) {
temp=a[y];
a[y]=a[g];
a[g]=temp;
y++;
}
}
temp=a[y-1];
a[y-1]=a[l];
a[l]=temp;
quickSort(a,l,y-1);
quickSort(a,y,r);
}
0 comments :
Post a Comment