Created
November 26, 2014 21:26
-
-
Save EugenyB/51a9f4c8451f8a04d034 to your computer and use it in GitHub Desktop.
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
void quickSort(int arr[], int size); | |
void sort(int a[], int left, int right) { | |
// На входе - массив a[] и пределы сортировки | |
int i = left, j = right-1; // поставить указатели на исходные места | |
int temp, p; | |
p = a[ (i + j) / 2 ]; // центральный элемент | |
// процедура разделения | |
do { | |
while ( a[i] < p ) i++; | |
while ( a[j] > p ) j--; | |
if (i <= j) { | |
temp = a[i]; a[i] = a[j]; a[j] = temp; | |
i++; j--; | |
} | |
} while ( i<=j ); | |
// рекурсивные вызовы, если есть, что сортировать | |
if ( j > left ) sort(a, left, j+1); | |
if ( i < right-1 ) sort(a, i, right); | |
} | |
void quickSort(int arr[], int size) | |
{ | |
sort(arr, 0, size); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment