Updated: 25 - Container Adapters
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user