0% found this document useful (0 votes)
30 views

C Program For Quick Sorting - Docx Main

This C program implements quicksort to sort an array of integers. It takes user input for the array size and elements, calls the qsort function to recursively sort the array, and prints out the sorted array. The qsort function performs the quicksort algorithm by picking a pivot element, partitioning the array around it, and recursively calling itself on the subarrays.

Uploaded by

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

C Program For Quick Sorting - Docx Main

This C program implements quicksort to sort an array of integers. It takes user input for the array size and elements, calls the qsort function to recursively sort the array, and prints out the sorted array. The qsort function performs the quicksort algorithm by picking a pivot element, partitioning the array around it, and recursively calling itself on the subarrays.

Uploaded by

neeraj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

/*c program for quick sorting*/

#include<stdio.h>
#include<conio.h>
void qsort(int arr[20], int fst, int last);
int main()
{
int arr[30];
int i,size;
printf("Enter total no. of the elements :
");
scanf("%d",&size);
printf("Enter total %d elements :
\n",size);
for(i=0; i<size; i++)
scanf("%d",&arr[i]);
qsort(arr,0,size-1);
printf("Quick sorted elements are as :
\n");
for(i=0; i<size; i++)
printf("%d\t",arr[i]);
getch();
return 0;
}
void qsort(int arr[20], int fst, int last)
{

int i,j,pivot,tmp;
if(fst<last)
{
pivot=fst;
i=fst;
j=last;
while(i<j)
{
while(arr[i]<=arr[pivot] && i<last)
i++;
while(arr[j]>arr[pivot])
j--;
if(i<j)
{
tmp=arr[i];
arr[i]=arr[j];
arr[j]=tmp;
}
}
tmp=arr[pivot];
arr[pivot]=arr[j];
arr[j]=tmp;
qsort(arr,fst,j-1);
qsort(arr,j+1,last);

}
}
/********* OUTPUT **********/

Screen-shot of quick sorting C program

You might also like