Use this:
typedef std::map<int,int> container_t;
void pushElement(container_t &cont, int value)
{
container_t::const_iterator it = cont.find(value);
cont[value] = 1 + (it == cont.end() ? 0: it->second);
}
If you also need a stack (for popping), you may need two containers:
- A stack for popping.
- A map for frequencies (histogram)
In this case, consider encapsulating both containers in a class of your own.
Hope this helps,