Monday, March 23, 2009

QUICK SORT

EXAMPLE-9:-------(Program to implement Quick sort)

#include
#include
void main()
{
int i,n,c,s,q,a[50],b[50];
clrscr();
printf("\n\t\t quick sort");
printf("\n\t\t***********");
printf("\n\t enter the no of elements:");
scanf("%d",&n);
printf("\n\t enter the values 1 by 1 :");
for(i=1;i<=n;i++) { scanf("\t %d",&a[i]); b[i]=a[i]; } q=n; s=1; quick(a,s,q); printf("\n\t before sorted\t after quicksort"); for(i=1;i<=n;i++) { printf("\n\t\t%d\t\t\t%d",b[i],a[i]); } getch(); return; } quick(int c[50],int m,int n) { int i=0,j,t,k; if(mk);
if(i {
t=c[i];
c[i]=c[j];
c[j]=t;
}
else
goto a2;
goto a1;
a2:
t=c[m];
c[m]=c[j];
c[j]=t;
quick(c,m,j-1);
quick(c,j+1,n);
}
return;
}

No comments:

Post a Comment