magnum opus
This commit is contained in:
parent
79416aa255
commit
33e60cd710
1 changed files with 4 additions and 7 deletions
11
main.cpp
11
main.cpp
|
@ -21,8 +21,6 @@ std::vector<std::size_t> getReversalsToSort(const std::vector<int> &arr) {
|
|||
std::vector<int> intermediate = arr;
|
||||
std::vector<std::size_t> ret = {};
|
||||
|
||||
// a bit more explicit than necessary but my brain thought it was useful info
|
||||
;
|
||||
for (std::size_t i = intermediate.size(); i > 1; i--) {
|
||||
|
||||
// only searching the unsorted elements
|
||||
|
@ -33,15 +31,14 @@ std::vector<std::size_t> getReversalsToSort(const std::vector<int> &arr) {
|
|||
std::size_t second_swap = i;
|
||||
// remove false positives of elements already being in the correct spot
|
||||
if (first_swap != second_swap) {
|
||||
// also remove reverses where nothing changes
|
||||
// if the element is already the first in the list we don't need to move
|
||||
// it there
|
||||
if (first_swap > 1) {
|
||||
ret.push_back(first_swap);
|
||||
std::reverse(intermediate.begin(), intermediate.begin() + first_swap);
|
||||
}
|
||||
if (second_swap > 1) {
|
||||
ret.push_back(second_swap);
|
||||
std::reverse(intermediate.begin(), intermediate.begin() + second_swap);
|
||||
}
|
||||
ret.push_back(second_swap);
|
||||
std::reverse(intermediate.begin(), intermediate.begin() + second_swap);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue