diff options
author | Sven Göthel <[email protected]> | 2024-04-24 01:09:49 +0200 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-04-24 01:09:49 +0200 |
commit | 49d81cc1fc56f01f76240f4a7346aa5ee17eae50 (patch) | |
tree | 63b70ed50243c4f04115bdec21224d908ca6a26f /src/lesson40_algo12.cpp | |
parent | f78ff02a7929b845dbbb306e20f073db8cf06a44 (diff) |
lesson40_algo12: hoare2: Cleanup my own partitioning trial
Diffstat (limited to 'src/lesson40_algo12.cpp')
-rw-r--r-- | src/lesson40_algo12.cpp | 39 |
1 files changed, 1 insertions, 38 deletions
diff --git a/src/lesson40_algo12.cpp b/src/lesson40_algo12.cpp index 2e8580c..23603bc 100644 --- a/src/lesson40_algo12.cpp +++ b/src/lesson40_algo12.cpp @@ -232,7 +232,7 @@ namespace hoare2 { using namespace impl_common; /** - * Hoare alike partitioning of range [b..e). + * Hoare alike quicksort of range [b..e). * * Difference to Hoare's partitioning is using dedicated loops for each side of the pivot * to move the element over to the other side. @@ -247,43 +247,6 @@ namespace hoare2 { * @param array * @param b left start index, inclusive * @param e right end index, exclusive - * @return pivot index - */ - template<typename V> - size_t partition(std::vector<V>& array, size_t b, size_t e) { - // stick with using references for comparison, no copy - size_t l = (b + e - 1 ) / 2; // pivot index - for(size_t i = b; i < l; ) { - if( array[i] > array[l] ) { - array.insert(array.begin() + e, array[i]); - array.erase( array.begin() + i ); - --l; - } else { - ++i; - } - } - for(size_t i = l+1; i < e; ) { - if( array[i] < array[l] ) { - array.insert(array.begin() + b, array[i]); - ++i; - ++l; - array.erase( array.begin() + i ); - } else { - ++i; - } - } - return l; - } - - /** - * Hoare alike quicksort of range [b..e). - * - * Quicksort by Tony Hoare in 1959, published 1961. - * - * @tparam V - * @param array - * @param b left start index, inclusive - * @param e right end index, exclusive * @return number of partitioning */ template<typename V> |