Search
 
SCRIPT & CODE EXAMPLE
 

C

function for quicksort in c

#include<stdio.h>

void swap(int* a, int* b)

{

int t = *a;

*a = *b;

*b = t;

}

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

{

int pivot = arr[high];

int i = (low - 1);

for (int j = low; j <= high- 1; 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)

{

int i;

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

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

printf("n");

}

int main()

{

int arr[] = ;

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

quickSort(arr, 0, n-1);

printf("The sorted array is: n");

printArray(arr, n);

return 0;

}
Comment

quicksort in c

int cmpfunc (const void * a, const void * b) {
   return ( *(int*)a - *(int*)b );
}
Comment

PREVIOUS NEXT
Code Example
C :: how to create calculator with switch in c 
C :: find length of int number in c 
C :: stdio 
C :: differnce between spooling and buffering 
C :: arduino millis 
C :: Graphics in C Draw Circle 
C :: take long long input in c 
C :: pthread c 
C :: how to modulo in c without use the operator 
C :: odd even in c with ternary operator 
C :: bash while loop n times 
C :: c to llvm 
C :: ruby find object in array by attribute 
C :: binary to decimal in c 
C :: Write a C program to merge two array to third array. 
C :: equal string c 
C :: mount cifs 
C :: passing two dimensional array to function in c 
C :: bubble sort 
C :: rust cross compile 
C :: pop and push shows black screen which needs to be pressed back flutter 
C :: ecrire programme en C une fonction remplir tableau et un fonction inverser 
C :: why do you jerk while falling aslee 
C :: C program to find power of any number 
C :: compile multiple c files 
C :: calling of a void in c 
C :: linear and binary search 
C :: string to number in c 
C :: Syntax for creating a node 
C :: block quote in lua 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =