Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
43 views

Quick Sort

This document provides code for implementing quicksort in C to sort a list of integers in ascending order. It includes code to: 1) Define functions for quicksort and main 2) Get user input for number of elements and store in array 3) Call quicksort function to recursively sort partitions of the array from left to right around a pivot

Uploaded by

gouse1210
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Quick Sort

This document provides code for implementing quicksort in C to sort a list of integers in ascending order. It includes code to: 1) Define functions for quicksort and main 2) Get user input for number of elements and store in array 3) Call quicksort function to recursively sort partitions of the array from left to right around a pivot

Uploaded by

gouse1210
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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