diff --git a/task2/include/quicksort_mt.h b/task2/include/quicksort_mt.h index d5f0050..f918818 100644 --- a/task2/include/quicksort_mt.h +++ b/task2/include/quicksort_mt.h @@ -36,7 +36,7 @@ private: std::swap(*lefti, *righti); } - return {std::span(data.begin(), pivot - 1), std::span(pivot + 1, data.end())}; + return {std::span(data.begin(), pivot), std::span(pivot, data.end())}; } @@ -50,9 +50,18 @@ private: } } - auto res = parition(data); - auto &left = res.first; - auto &right = res.second; + auto pivot = data[std::distance(data.begin(), data.end()) / 2]; + + auto m1 = std::partition(data.begin(), data.end(), [pivot, this](const auto &em) { + return this->cmp(em, pivot); + }); + + auto m2 = std::partition(m1, data.end(), [pivot, this](const auto &em) { + return !(this->cmp(em, pivot)); + }); + + auto left = data.subspan(0, m1 - data.begin()); + auto right = data.subspan(m2 - data.begin(), data.size()); if (depth < mdepth) { std::thread left_thread([&]() { qsort(left, depth + 1, mdepth); });