A blog to help students to learn programming in various languages including C, C++, Java, Python and many more.

Subscribe For Free Latest Updates!

We'll not spam mate! We promise.

Saturday, 16 January 2016



Program ScreenShot

#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



Copyright © 2016 - ProgrmIt - All Rights Reserved
(Articles Cannot Be Reproduced Without Author Permission.)
Design By : | Powered By: Blogger