#include<iostream>
using namespace std;
int main()
{
int A[7]={3,6,1,2,7,5,4};
void quicksort(int[],int,int);
quicksort(A,0,6);
for(int i=0;i<7;i++)
{
cout<<A[i]<<" ";
}
cout<<endl;
return 0;
}
void quicksort(int A[7],int low,int high)
{
if(low>=high)
{
return;
}
int p=A[low];
int i=low+1;
int j=high;
while(j>=i)
{
while(A[i]<=p)
{
i++;
}
while(A[j]>p)
{
j--;
}
if(j>i)
{
int t=A[i];
A[i]=A[j];
A[j]=t;
}
}
int t=A[j];
A[j]=A[low];
A[low]=t;
quicksort(A,low,j-1);
quicksort(A,j+1,high);
}
A blog on programming and software design interview problems and solutions. Also there are some application development related stuff.
Pages
Tuesday, August 7, 2012
C++ Program for Quicksort
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment