You are on page 1of 1

Name of the Program:week8a

Week 8:Write C programs for implementing the following sorting methods to arrange a list of
integers inascending order:a) Quick sort
#include<stdio.h>
a[i]=a[j];
void qsort(int a[10],int first,int last);
a[j]=t;
int main()
}
{
}
int i,n,a[10],j,pivot,last,t;
t=a[pivot];
printf("enter the no of elements\n");
a[pivot]=a[j];
scanf("%d",&n);
a[j]=t;
printf("enter the elements\n");
qsort(a,first,j-1);
for(i=0;i<n;i++)
qsort(a,j+1,last);
scanf("%d",&a[i]);
qsort(a,0,n-1);
}
printf("sorted elements is\n");
}
for(i=0;i<n;i++)
Output:
printf("\n%d",a[i]);
$ ./a.out
}
enter the no of elements
void qsort(int a[10],int first,int last)
6
{
enter the elements
int i,j,t,pivot,n;
34
if(first<last)
23
{
45
i=first;
12
j=last;
56
pivot=first;
10
while(i<j)
sorted elements is
{
while(a[i]<=a[pivot]&&i<last)
10
i++;
12
while(a[j]>a[pivot])
23
j--;
34
if(i<j)
45
{
56[13r21a0507@mysqldbserver week8]$
t=a[i];

You might also like