git-svn-id: svn://db.shs.com.ru/pip@681 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2019-01-24 14:42:00 +00:00
parent 8ba3d5dc8e
commit 0e06a7b003

View File

@@ -38,21 +38,36 @@ __PIVECTOR_SIMPLE_TYPE__(T)
template<class T> template<class T>
void piQuickSort(T * a, ssize_t N) { void piQuickSort(T * a, ssize_t N) {
if (N < 1) return; if (N < 1) return;
ssize_t i = 0, j = N; if (N < 47) {
T & p(a[N >> 1]); T tmp;
do { ssize_t i,j;
while (a[i] < p) i++; for(i=1; i<N; i++) {
while (a[j] > p) j--; tmp = a[i];
if (i <= j) { j = i-1;
if (i != j) { while(tmp<a[j] && j>=0)
//piCout << "swap" << i << j << a[i] << a[j]; {
piSwapBinary<T>(a[i], a[j]); a[j+1] = a[j];
j = j-1;
} }
i++; j--; a[j+1] = tmp;
} }
} while (i <= j); } else {
if (j > 0) piQuickSort(a, j); ssize_t i = 0, j = N;
if (N > i) piQuickSort(a + i, N - i); T & p(a[N >> 1]);
do {
while (a[i] < p) i++;
while (a[j] > p) j--;
if (i <= j) {
if (i != j) {
//piCout << "swap" << i << j << a[i] << a[j];
piSwapBinary<T>(a[i], a[j]);
}
i++; j--;
}
} while (i <= j);
if (j > 0) piQuickSort(a, j);
if (N > i) piQuickSort(a + i, N - i);
}
} }
template <typename Key, typename T> template <typename Key, typename T>