I have to store the number of occurences of each number (C++). An example input can look like this:
1
2
2
1
1
after the data is stored, I can use it in a stack fashion (I will always need the number of occurences of 2 first and only then 1, for example). Is it ok to take the input using a multiset, and then move the data to a stack (the number of inputs can be large and time complexity is a priority), as I am a little confused here.
It sounds like you want a
std::priority_queuebased on the count of each of the numbers.It could look like this:
Demo