Updated: 25 - Container Adapters

This commit is contained in:
2026-08-16 09:41:15 +03:00
parent 362ef757b3
commit 00a5178b01
@@ -1,7 +1,6 @@
#include "container_adapters.hpp" #include "container_adapters.hpp"
#include <algorithm> #include <algorithm>
#include <map>
#include <set> #include <set>
namespace stl_containers { namespace stl_containers {
@@ -42,11 +41,9 @@ auto simulate_queue(const std::vector<int>& arrivals) -> std::vector<int> {
} }
auto top_k_largest(const std::vector<int>& data, const int k) -> std::vector<int> {; auto top_k_largest(const std::vector<int>& data, const int k) -> std::vector<int> {;
auto v = std::vector<int>{};
std::ranges::for_each(data, [&v](const auto& p){v.push_back(p);});
// Remove duplicates // Remove duplicates
std::set<int> s{v.begin(), v.end()}; std::set<int> s{data.begin(), data.end()};
v = std::vector<int>{s.begin(), s.end()}; auto v = std::vector<int>{s.begin(), s.end()};
std::ranges::sort(v, std::ranges::greater{}); std::ranges::sort(v, std::ranges::greater{});
v.resize(k); v.resize(k);
return v; return v;