Code optimizations
- use prefix `++` and `--` - removed obsolete braces
This commit is contained in:
@@ -3,9 +3,7 @@
|
||||
namespace c0ding::algorithm {
|
||||
template<class T>
|
||||
void quick::sort(std::vector<T>& list) {
|
||||
if (list.size() > 1) {
|
||||
_quick<T>(list.begin(), --list.end());
|
||||
}
|
||||
if (list.size() > 1) _quick<T>(list.begin(), --list.end());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -16,25 +14,17 @@ namespace c0ding::algorithm {
|
||||
const long pivot = *mid;
|
||||
|
||||
while (std::distance(i, j) >= 0) {
|
||||
while (*i < pivot) {
|
||||
i++;
|
||||
}
|
||||
while (*j > pivot) {
|
||||
j--;
|
||||
}
|
||||
while (*i < pivot) ++i;
|
||||
while (*j > pivot) --j;
|
||||
|
||||
if (std::distance(i, j) >= 0) {
|
||||
std::iter_swap(i, j);
|
||||
i++;
|
||||
j--;
|
||||
++i;
|
||||
--j;
|
||||
}
|
||||
}
|
||||
|
||||
if (std::distance(left, j) > 0) {
|
||||
_quick<T>(left, j);
|
||||
}
|
||||
|
||||
if (std::distance(i, right) > 0) {
|
||||
_quick<T>(i, right);
|
||||
}
|
||||
if (std::distance(left, j) > 0) _quick<T>(left, j);
|
||||
if (std::distance(i, right) > 0) _quick<T>(i, right);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user