0% found this document useful (0 votes)
5 views2 pages

Quick Sort Algorithm in C

The document contains a C program that implements the Quick Sort algorithm to sort an array of integers. It prompts the user to enter the size and elements of the array, sorts them using the Quick Sort method, and then displays the sorted array. The program utilizes functions for swapping elements and performing the sorting process recursively.

Uploaded by

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

Quick Sort Algorithm in C

The document contains a C program that implements the Quick Sort algorithm to sort an array of integers. It prompts the user to enter the size and elements of the array, sorts them using the Quick Sort method, and then displays the sorted array. The program utilizes functions for swapping elements and performing the sorting process recursively.

Uploaded by

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

PROGRAM

#include<stdio.h>
#include<conio.h>
int a[10];
void swap(int a[10], int k, int c)
{
int temp;
temp = a[k];
a[k] = a[c];
a[c] = temp;
}
void quick(int a[10], int left, int right)
{
int pivot, i, j;
if(left < right)
{
i = left;
j = right + 1;
pivot = a[left];
do
{
do
i++;
while(a[i] < pivot);
do
j--;
while(a[j] > pivot);
if(i < j)
swap(a, i, j);
} while(i < j);
swap(a, left, j);
quick(a, left, j - 1);
quick(a, j + 1, right);
}
}
void main()
{
int i, n;
clrscr();
printf("Enter the size of the Array\n");
scanf("%d", &n);
printf("Enter the elements of the Array\n");
for(i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
quick(a, 0, n - 1);
printf("Sorted Array:\n");
for(i = 0; i < n; i++)
printf("%d\t", a[i]);
printf("\n");
getch();
}
OUTPUT
Enter the size of the Array
5
Enter the elements of the Array
50 20 10 40 30
Sorted Array:
10 20 30 40 50

You might also like