mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-08 04:08:32 +00:00
Add more CTL content
This commit is contained in:
parent
38921dc46b
commit
021c53ba32
56 changed files with 1747 additions and 298 deletions
29
ctl/partition.h
Normal file
29
ctl/partition.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-
|
||||
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
|
||||
#ifndef CTL_PARTITION_H_
|
||||
#define CTL_PARTITION_H_
|
||||
#include "utility.h"
|
||||
|
||||
namespace ctl {
|
||||
|
||||
template<typename RandomIt, typename Compare>
|
||||
RandomIt
|
||||
partition(RandomIt first, RandomIt last, Compare comp)
|
||||
{
|
||||
auto pivot = *ctl::move(last - 1);
|
||||
auto i = first - 1;
|
||||
|
||||
for (auto j = first; j < last - 1; ++j) {
|
||||
if (comp(*j, pivot)) {
|
||||
++i;
|
||||
ctl::swap(*i, *j);
|
||||
}
|
||||
}
|
||||
|
||||
ctl::swap(*(i + 1), *(last - 1));
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
} // namespace ctl
|
||||
|
||||
#endif // CTL_PARTITION_H_
|
Loading…
Add table
Add a link
Reference in a new issue