BAN: implement exchange sort and test for it

This commit is contained in:
2023-12-07 10:16:15 +02:00
parent e935a33a4d
commit 43458cc74f
4 changed files with 74 additions and 0 deletions

20
BAN/include/BAN/Sort.h Normal file
View File

@@ -0,0 +1,20 @@
#pragma once
#include <BAN/Swap.h>
#include <BAN/Traits.h>
namespace BAN
{
template<typename It, typename Comp = less<typename It::value_type>>
void sort_exchange(It begin, It end, Comp comp = {})
{
for (It lhs = begin; lhs != end; ++lhs)
for (It rhs = lhs; ++rhs != end;)
if (!comp(*lhs, *rhs))
swap(*lhs, *rhs);
}
}