From 258c64ed031e5526bc7a312571c14130527512f1 Mon Sep 17 00:00:00 2001 From: Shahyah Darioosh <97061335+Shordore@users.noreply.github.com> Date: Tue, 6 Feb 2024 17:33:15 -0500 Subject: [PATCH] Add files via upload --- Frequency_Element.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Frequency_Element.cpp diff --git a/Frequency_Element.cpp b/Frequency_Element.cpp new file mode 100644 index 000000000..5cf5c8701 --- /dev/null +++ b/Frequency_Element.cpp @@ -0,0 +1,26 @@ +#include +#include +#include + +std::unordered_map FrequencyElement(const std::vector& nums) { + std::unordered_map un_map; + + for (int i : nums) { + un_map[i]++; + } + + return un_map; +} + + +int main() { + std::vector inputArray = {1, 2, 3, 1, 2, 1, 4, 5, 4, 3}; + + std::unordered_map result = FrequencyElement(inputArray); + + for (const auto& pair : result) { + std::cout << "Element: " << pair.first << ", Frequency: " << pair.second << std::endl; + } + + return 0; +}