Quick sort is the one of the most efficient method to sort the elements. 1. Select a pivot element. 2. Partition the array around pivot 3. Move the elements such that all elements less than partition element should come before the elements greater than pivot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

#include<stdio.h> int P(int arr[], int left, int right) { int pivot = arr[(left+right)/2]; while(arr[left] < pivot) left++; while(arr[right] > pivot) right; if(left <= right) { int temp= arr[left]; arr[left] = arr[right]; arr[right] = temp; left++; right; } return left; } int Q(int arr[], int left, int right) { int index = P(arr,left, right); if( left < index 1) Q(arr, left, index 1); if( index < right) Q( arr, index, right); return 1; } int main(void) { int arr[] = {4,2,3,9,10,8,7}; for(int i =0 ;i < 7; i++) printf(" %d", arr[i]); printf("\n"); Q(arr, 0, 6); for(int i =0 ;i < 7; i++) printf(" %d", arr[i]); return 0; } 
Continue reading →