diff --git a/main.cpp b/main.cpp index e43729e..e50e252 100644 --- a/main.cpp +++ b/main.cpp @@ -21,8 +21,6 @@ std::vector getReversalsToSort(const std::vector &arr) { std::vector intermediate = arr; std::vector 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 getReversalsToSort(const std::vector &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); } }