Skip to content

Instantly share code, notes, and snippets.

@YassineBajdou
Created January 11, 2019 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YassineBajdou/7609eebff77386eb38fcdfafb43ccc69 to your computer and use it in GitHub Desktop.
Save YassineBajdou/7609eebff77386eb38fcdfafb43ccc69 to your computer and use it in GitHub Desktop.
Quick Sort
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