Skip to content

Instantly share code, notes, and snippets.

@AbinashBishoyi
Created February 27, 2012 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbinashBishoyi/1921390 to your computer and use it in GitHub Desktop.
Save AbinashBishoyi/1921390 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<stdlib.h>
#include<sys/time.h>
using namespace std;
class quick
{
public:
int partition(int a[],int high ,int low);
void callsort(int a[],int high ,int low);
};
int quick::partition(int a[],int high,int low)
{
int i=low+1;
int j=high;
int key=a[low];
cout<<i<<j<<key;
while(1)
{
while (i<high && a[i]<key)
i++;
while(j>low && a[j]>=key)
j--;
if(i<j)
{
int temp =a[i];
a[i]=a[j];
a[j]=temp;
}
else
{
int temp=a[j];
a[j]=key;
key=temp;
}
}
return j;
}
void quick::callsort(int a[],int high,int low)
{
while(low<high)
{
int j;
j=partition(a,low,high);
callsort(a,low,j-1);
callsort(a,j+1,high);
}}
main()
{
int a[10000];
int n=5;
cout<<"enter the elements u wish to sort";
for(int k=0;k<n;k++) // having infinite loop here
cin>>a[k];
quick q;
q.callsort(a,n-1,0);
cout<<"the sorted array is";
for(int l=0;l<n;l++)
cout<<a[l]<<"\t" ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment