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