Updated: 25 - Container Adapters
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#include "container_adapters.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
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 v = std::vector<int>{};
|
||||
std::ranges::for_each(data, [&v](const auto& p){v.push_back(p);});
|
||||
// Remove duplicates
|
||||
std::set<int> s{v.begin(), v.end()};
|
||||
v = std::vector<int>{s.begin(), s.end()};
|
||||
std::set<int> s{data.begin(), data.end()};
|
||||
auto v = std::vector<int>{s.begin(), s.end()};
|
||||
std::ranges::sort(v, std::ranges::greater{});
|
||||
v.resize(k);
|
||||
return v;
|
||||
|
||||
Reference in New Issue
Block a user