By the way, if you're doing this a lot (adding things to a set in arbitrary order and then removing the top element), you could also take a look at std::priority_queue see whether that suits your usage.
If (!setInt.empty()) { std::set::iterator it = setInt.end(); --it; setInt. Erase(it); } By the way, if you're doing this a lot (adding things to a set in arbitrary order and then removing the top element), you could also take a look at std::priority_queue, see whether that suits your usage.
Muntoo: if not, hopefully someone will comment to say in what way it differs. – Steve Jessop Dec 14 at 10:10 Oh, whoops, I thought that if was a for loop for some reason... – muntoo Dec 15 at 3:30.
In C++11 setInt. Erase(std::prev(setInt.end())); You can decide how you want to handle cases where the set is empty.
I'd propose using a different name for rbegin which has a proper type: setInt. Erase(--setInt.end()); Assuming you checked that setInt is not empty! Btw.
This works because you can call the mutating decrement operator on a temporary (of type std::set::iterator). This temporary will then be passed to the erase function.
Cunning, because unlike std::vector::iterator, there's no way that std::set::iterator can be a pointer. It must be a class type, so temporaries must be decrementable. – Steve Jessop Dec 14 at 10:15 @SteveJessop: They are :) – bitmask Dec 14 at 10:18.
Check if the set is empty or not. If not, then get the last element and set that as iterator and reduce that iterator and erase the last element. If (!setInt.empty()) { std::set::iterator it = setInt.end(); --it; if(it!
= setInt.end()) { setInt. Erase(it); } }.
If you want to delete 4 instead of the last you should use the find method. Depending on the use case 4 might not be the last. Std::set::iterator it = setInt.
Find(4); if(it! = setInt.end()) { setInt. Erase(it); } If you want to delete the last element use: if (!setInt.empty()) { setInt.
Erase(--setInt.rbegin().base()); // line above is equal to // setInt. Erase(--setInt.end()); } While I was not sure if --*.end(); is O.K. I did some reading. So the -- on rbegin().base() leads to the same result as -- on end().
And both should work.
SetInt.rend() returns an iterator that points before setInt.begin(), so it has nothing to do with the end of the set. – wigy Dec 13 at 20:35 you are right rbegin I intended to write. :-( I fix this – Totonga Dec 14 at 7:05 1 How is your proposal different from the one in the question, which as we already know doesn't work?
– bitmask Dec 14 at 7:25 so I try again :-) with a lottle change. I should read before write :-) – Totonga Dec 14 at 9:27.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.