#include <stdio.h> void quickSort( int[], int, int); int partition( int[], int, int); int main() { int i , n ; printf("Please Enter Array Length:\n"); scanf("%d",&n); int a[n]; printf("Enter %d Array Element:\n",n); for(i=0;i<n;i++){ scanf("%d",&a[i]); } printf("\n\nUnsorted array is: "); for(i = 0; i < n; ++i) { printf(" %d ", a[i]); } quickSort( a, 0, n-1); printf("\n\nSorted array is: "); for(i = 0; i < n ; ++i) printf(" %d ", a[i]); return 0; } void quickSort( int a[], int lower, int upper) { int j; if( lower < upper ) { j = split( a, lower, upper); quickSort( a, lower, j-1); quickSort( a, j+1, upper); } } int split ( int a[ ], int lower, int upper ) { int i, p, q, t ; p = lower + 1 ; q = upper ; i = a[lower] ; while ( q >= p ) { while ( a[p] < i ) p++ ; while ( a[q] > i ) q-- ; if ( q > p ) { t = a[p] ; a[p] = a[q] ; a[q] = t ; } } t = a[lower] ; a[lower] = a[q] ; a[q] = t ; return q ; }
Most Popular
-
Befunge: Developed by : Chris Pressey Year: 1993 ...
-
-
The list below is an unordered list. You can pick any...
-
Recursion happens when function calls itself directly...
Copyrights © 2016 Codzya. Powered by Blogger.
Monday, May 2, 2016
Subscribe to:
Post Comments (Atom)
- Recent
- Weekly
- Comment
Recent
As a task executes it utilizes the processor...
Sep 25 2016 | Read moreMemory leak occurs when programmers create a memory in heap and...
Aug 19 2016 | Read moreBefunge: Developed by : Chris Pressey Year: 1993 Stack-based,...
May 19 2016 | Read more1- The C Programming Language This book is a comprehensive...
May 18 2016 | Read more1. Java The tech community recently celebrated the 20th...
May 17 2016 | Read more
Weekly
-
Befunge: Developed by : Chris Pressey Year: 1993 ...
-
-
The list below is an unordered list. You can pick any...
-
Recursion happens when function calls itself directly...
-
1- The C Programming Language This book is a...
Comment
Get this Recent Comments Widget
0 Comment to "Quick Sort "
Post a Comment