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

Aoa 2

The document contains a C program to implement quicksort algorithm to sort an array of integers. It includes functions to partition the array and recursively call quicksort on subarrays. The main function takes input array, calls quicksort and prints sorted output.

Uploaded by

achaurasia22ecs
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)
7 views2 pages

Aoa 2

The document contains a C program to implement quicksort algorithm to sort an array of integers. It includes functions to partition the array and recursively call quicksort on subarrays. The main function takes input array, calls quicksort and prints sorted output.

Uploaded by

achaurasia22ecs
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
You are on page 1/ 2

Program :-

#include <stdio.h>
#include <conio.h>
int partition(int a[], int left, int right) {
int pivot = a[left];
int i = left + 1;
int j = right;
int temp;
do {
while (a[i] <= pivot) i++;
while (a[j] > pivot) j--;
if (i < j) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
} while (i < j);
temp = a[left];
a[left] = a[j];
a[j] = temp;
return j;
}
void quickSort(int a[], int left, int right) {
int partIndex;
if (left < right) {
partIndex = partition(a, left, right);
quickSort(a, left, partIndex - 1);
quickSort(a, partIndex + 1, right);
}
}
int main() {
int arr[20], i, n;
clrscr();
printf("Name:Aditi Gharat");
printf("\nDiv:A Roll no:319");
printf("\nEnter no. of elements in array: ");
scanf("%d", &n);
printf("Enter elements in array:\n");
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
quickSort(arr, 0, n - 1);
printf("The sorted array is:\n");
for (i = 0; i < n; i++) {
printf("%d\t", arr[i]);
}
getch();
return 0;
}

Output :-

You might also like