I need to get the last element from an unordered_set, and it must be using the unordered_set, not any other class. (mostly because I'm to modify lots of code already done) but by what I've been looking the only possible way is iterate over it and save the element and then return it. But in big sets it would be too slow. besides I tried this and did not work.
unordered_set <int>::iterator it = frames.end();
--it;
I got the following error: "no match for 'operator--' in '--it'"
Its kind of useful mostly because of this, it stores the data in a "stack" way, as following:
unordered_set<int> s;
s.insert(9);
s.insert(4);
s.insert(8);
s.insert(0);
s.insert(1);
unordered_set<int>::iterator it = s.end();
for( it = s.begin(); it!= s.end(); ++it )
cout << *(it) << " ";
it prints:"1 0 8 4 9"
So the "last" element would be always 9, it is the "first" element that was inserted, as I said before in a "stack" way.
Any idea to improve it?