init commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
#include <iterator>
|
||||
|
||||
template <typename Container>
|
||||
typename Container::value_type process(const Container& container) {
|
||||
using ValueType = typename Container::value_type;
|
||||
|
||||
if (container.empty()) {
|
||||
return ValueType{};
|
||||
}
|
||||
|
||||
auto it = container.rbegin();
|
||||
ValueType sum = *it;
|
||||
|
||||
for (int i = 0; it != container.rend() && i < 5; ++i, ++it) {
|
||||
if (i == 2 || i == 4) {
|
||||
sum += *it;
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// #include <iostream>
|
||||
// #include <vector>
|
||||
#include <iterator>
|
||||
|
||||
template <typename Container, typename Predicate>
|
||||
Container myfilter(const Container& container, Predicate pred) {
|
||||
Container result;
|
||||
|
||||
for (const auto& x : container) {
|
||||
if (pred(x)) {
|
||||
result.insert(result.end(), x);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <iterator>
|
||||
#include <functional>
|
||||
|
||||
template <typename ForwardIt, typename Compare = std::less<>>
|
||||
void selection_sort(ForwardIt first, ForwardIt last, Compare comp = Compare()) {
|
||||
for (auto fit = first; fit != last; ++fit) {
|
||||
auto min_it = fit;
|
||||
|
||||
for (auto sit = std::next(fit); sit != last; ++sit) {
|
||||
if (comp(*sit, *min_it)) {
|
||||
min_it = sit;
|
||||
}
|
||||
}
|
||||
|
||||
std::swap(*fit, *min_it);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user