Source Code:
#include<iostream.h>
#include<conio.h>
void quicksort(int*,int,int);
int partion(int*,int,int);
void main()
{clrscr();
cout<<"Enter ten number for quick sort by-Tarun rawat:\n\n";
int a[10];
for(int i=0;i<10;i++)
{cin>>a[i];
}
int p=0,q=9;
quicksort(a,p,q);
cout<<"After applying quick sort :\n";
for(i=0;i<10;i++)
{cout<<a[i]<<" ";
}
getch();
}
void quicksort(int a[],int p,int q)
{ if(p<q)
{int r=partion(a,p,q);
quicksort(a,p,r-1);
quicksort(a,r+1,q);
}
}
int partion(int a[],int p,int q)
{ int x=a[p];
int i=p;int temp;
for(int j=p+1;j<=q;j++)
{ if(a[j]<= x)
{i=i+1;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
temp=a[p];
a[p]=a[i];
a[i]=temp;
return i;
}
Welcome to " way2cplusplus.blogspot.in " Objective of this blog is to implement various Computer Science Engineering Lab problems into C++ programming language. These are basically most common Lab Exercise problems based on the curriculum of engineering colleges throughout the Nation. These lab exercises are also relevant to Data structure. Simply C++ programming zone...
No comments:
Post a Comment