#include<
#include<
using namespace std;
void qsort(int data[],int low,int high);
void main()
{
system("cls");
int data[50],n,c=1;
while(c==1)
{
cout<<"\nEnter the size of the array: "; cin>>n;
cout<<"\n\nEnter the elements of the array"; for(int i=0;i<
{
cin>>data[i];
cout<<"\n"; } getch(); qsort(data,0,n-1); cout<<"\nThe sorted array is: \n"; for(i=0;i<
{
cout<<" "<<data[i];
}
cout<<"\n\nPress 1 to continue: "; cin>>c;
}
}
void qsort(int data[],int low,int high)
{
int pivot,temp,i,j;
i=low;
j=high;
pivot=data[(low+high)/2];
while(i<=j) { while(data[i]<
i++;
while(pivot<data[j])
j--;
if(i<=j) { temp=data[i]; data[i]=data[j]; data[j]=temp; i++; j--; } } if(low<
(data,low,j);
if(i<
qsort(data,i,high);
}
- Benil Babu Mathew
No comments:
Post a Comment