parent
e732d062b6
commit
4144ab422e
@ -20,11 +20,13 @@ public:
|
||||
private:
|
||||
auto parition(std::span<T> &data) -> std::pair<std::span<T>, std::span<T>> {
|
||||
|
||||
auto pivot = data.begin();
|
||||
std::advance(pivot, std::distance(data.begin(), data.end()) / 2);
|
||||
std::vector<T> buf(data);
|
||||
|
||||
auto lefti = data.begin();
|
||||
auto righti = data.end();
|
||||
auto pivot = buf.begin();
|
||||
std::advance(pivot, std::distance(buf.begin(), buf.end()) / 2);
|
||||
|
||||
auto lefti = buf.begin();
|
||||
auto righti = buf.end();
|
||||
|
||||
while (1) {
|
||||
for (; cmp(*lefti, *pivot); lefti++);
|
||||
@ -37,6 +39,7 @@ private:
|
||||
std::swap(lefti, righti);
|
||||
}
|
||||
|
||||
std::move(buf.begin(), buf.end(), data.begin());
|
||||
return {std::span<T>(data.begin(), lefti), std::span<T>(lefti, data.end())};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user