BAN: Implement next() and prev() for iterators and use them in sorts

This commit is contained in:
2023-12-07 19:28:05 +02:00
parent 3bc7113cc5
commit 08bc0a2815
2 changed files with 33 additions and 2 deletions

View File

@@ -10,7 +10,7 @@ namespace BAN
void sort_exchange(It begin, It end, Comp comp = {})
{
for (It lhs = begin; lhs != end; ++lhs)
for (It rhs = lhs; ++rhs != end;)
for (It rhs = next(lhs, 1); rhs != end; ++rhs)
if (!comp(*lhs, *rhs))
swap(*lhs, *rhs);
}
@@ -21,7 +21,7 @@ namespace BAN
template<typename It, typename Comp>
It sort_quick_partition(It begin, It end, Comp comp)
{
It pivot = end; --pivot;
It pivot = prev(end, 1);
It it1 = begin;
for (It it2 = begin; it2 != pivot; ++it2)