[go: up one dir, main page]

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

Quick Sort

The document contains a C program that implements the Quick Sort algorithm to sort an array of integers. It includes functions for swapping elements, partitioning the array, performing the Quick Sort, and printing the sorted array. The main function initializes an array, calls the sorting function, and displays the sorted results.

Uploaded by

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

Quick Sort

The document contains a C program that implements the Quick Sort algorithm to sort an array of integers. It includes functions for swapping elements, partitioning the array, performing the Quick Sort, and printing the sorted array. The main function initializes an array, calls the sorting function, and displays the sorted results.

Uploaded by

sopkuateb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>

void swap(int *a, int *b) {

int temp = *a;

*a = *b;

*b = temp;

int partition(int arr[], int low, int high) {

int pivot = arr[high];

int i = (low - 1);

for (int j = low; j < high; j++) {

if (arr[j] < pivot) {

i++;

swap(&arr[i], &arr[j]);

swap(&arr[i + 1], &arr[high]);

return i + 1;

void quickSort(int arr[], int low, int high) {

if (low < high) {

int pi = partition(arr, low, high);


quickSort(arr, low, pi - 1);

quickSort(arr, pi + 1, high);

void printArray(int arr[], int size) {

for (int i = 0; i < size; i++) {

printf("%d ", arr[i]);

printf("\n");

int main() {

int arr[] = {10, 7, 8, 9, 1, 5};

int n = sizeof(arr) / sizeof(arr[0]);

quickSort(arr, 0, n - 1);

printf("Sorted array: \n");

printArray(arr, n);

return 0;

You might also like