Code optimizations

- use prefix `++` and `--`
- removed obsolete braces
This commit is contained in:
2026-05-03 14:22:31 +02:00
parent ade7d7bf73
commit 116c622b8b
+8 -18
View File
@@ -3,9 +3,7 @@
namespace c0ding::algorithm { namespace c0ding::algorithm {
template<class T> template<class T>
void quick::sort(std::vector<T>& list) { void quick::sort(std::vector<T>& list) {
if (list.size() > 1) { if (list.size() > 1) _quick<T>(list.begin(), --list.end());
_quick<T>(list.begin(), --list.end());
}
} }
template<class T> template<class T>
@@ -16,25 +14,17 @@ namespace c0ding::algorithm {
const long pivot = *mid; const long pivot = *mid;
while (std::distance(i, j) >= 0) { while (std::distance(i, j) >= 0) {
while (*i < pivot) { while (*i < pivot) ++i;
i++; while (*j > pivot) --j;
}
while (*j > pivot) {
j--;
}
if (std::distance(i, j) >= 0) { if (std::distance(i, j) >= 0) {
std::iter_swap(i, j); std::iter_swap(i, j);
i++; ++i;
j--; --j;
} }
} }
if (std::distance(left, j) > 0) { if (std::distance(left, j) > 0) _quick<T>(left, j);
_quick<T>(left, j); if (std::distance(i, right) > 0) _quick<T>(i, right);
}
if (std::distance(i, right) > 0) {
_quick<T>(i, right);
}
} }
} }