diff --git a/Hashing/countingfrequencies.cpp b/Hashing/countingfrequencies.cpp new file mode 100644 index 00000000..f59205d5 --- /dev/null +++ b/Hashing/countingfrequencies.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; + +void CountFreq(int arr[], int n) // function to count the frequency of the element +{ + unordered_map h; + for (int i = 0; i < n; i++) + { + h[arr[i]]++; + } + for (auto e : h) + { + cout << e.first << " " << e.second << endl; + } +} + +int main() +{ + int n; // size of the array + cin >> n; + int arr[n]; + for (int i = 0; i < n; i++) + { + cin >> arr[i]; + } + CountFreq(arr, n); + return 0; +} \ No newline at end of file