General Purpose library for Freestanding C++ and POSIX systems
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

43 rindas
1.1 KiB

#pragma once
#include <gp/algorithms/move.hpp>
namespace gp {
template<typename it_t, typename pred>
it_t lomuto_partition(it_t first, it_t last, pred predicate = pred{}) {
auto i = it_t(first);
auto j = first;
for(; j != last; ++j) {
if(predicate(*j)){
gp::swap(*i, *j);
++i;
}
}
return i;
}
template<typename it_t, typename pred>
it_t hoare_partition(it_t first, it_t last, pred predicate = pred{}) {
while(first != last) {
while(predicate(*first)) {
++first;
if(first == last) return first;
}
do {
--last;
if(first == last) return first;
} while(!predicate(*last));
swap(*first, *last);
++first;
}
return first;
}
/**
template<typename it_t, typename pred>
it_t partition(it_t first, it_t last, pred predicate = pred{}) {
return gp::hoare_partition(first, last, predicate);
}**/
}