Created
January 11, 2019 11:03
-
-
Save YassineBajdou/7609eebff77386eb38fcdfafb43ccc69 to your computer and use it in GitHub Desktop.
Quick Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int partition ( int A[],int start ,int end) { | |
int i = start + 1; | |
int piv = A[start] ; //make the first element as pivot element. | |
for(int j =start + 1; j <= end ; j++ ) { | |
/*rearrange the array by putting elements which are less than pivot | |
on one side and which are greater that on other. */ | |
if ( A[ j ] < piv) { | |
swap (A[ i ],A [ j ]); | |
i += 1; | |
} | |
} | |
swap ( A[ start ] ,A[ i-1 ] ) ; //put the pivot element in its proper place. | |
return i-1; //return the position of the pivot | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment