0% found this document useful (0 votes)
15 views3 pages

C QuickSort Program Example

The document describes a C program that implements quicksort to sort an array. The program takes input of array size and elements, calls the quicksort function with array name and indices as arguments, and prints the sorted array. The quicksort function recursively partitions the array around a pivot element and calls itself on the sub-arrays until the entire array is sorted.

Uploaded by

rahul
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

C QuickSort Program Example

The document describes a C program that implements quicksort to sort an array. The program takes input of array size and elements, calls the quicksort function with array name and indices as arguments, and prints the sorted array. The quicksort function recursively partitions the array around a pivot element and calls itself on the sub-arrays until the entire array is sorted.

Uploaded by

rahul
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROGRAM 11:PROGRAM TO PERFORM QUICKSORT

August 19, 2019 ON ARRAY IN C

#include<stdio.h>

#include<conio.h>

void quicksort(int list[],int low,int high);

void main()

clrscr();

int a[50],n,i;

printf("\nEnter size of array:");

scanf("%d",&n);

printf("\nEnter elemnets of array:\n");

for(i=0;i<n;i++)

scanf("%d",&a[i]);

quicksort(a,0,n-1);

printf("\nAfter applying quick sort:\n");

for(i=0;i<n;i++)

printf("%d\n",&a[i]);

getch();

void quicksort(int list[],int low,int high)

int pivot,i,j,temp

if(low<high)

{ pivot=low;

Vrinda Sharma Signature


18CE063
PROGRAM 11:PROGRAM TO PERFORM QUICKSORT
August 19, 2019 ON ARRAY IN C

i=low;

j=high;

while(i<j)

{ while(list[i]<=list[pivot] && i<=high)

i++;

while(list[j]>list[pivot] && j>=low)

j--;

if(i<j)

{ temp=list[i];

list[i]=list[j];

list[j]=temp;

temp=list[j];

list[j]=list[pivot];

list[pivot]=temp;

quicksort(list,low,j-1);

quicksort(list,j+1,high);

Vrinda Sharma Signature


18CE063
PROGRAM 11:PROGRAM TO PERFORM QUICKSORT
August 19, 2019 ON ARRAY IN C

OUTPUT:

Vrinda Sharma Signature


18CE063

You might also like