|Did you mean to initialize the iterators the other way around?|
Nope :) This way, Current ends up with the first iterator, and Next has the second. It only takes two lines of code. If I did it the other way around I'd have to make them both equal to Cost.begin(), then add a third line with Next++:
list<Mana>::iterator Current = Cost.begin();
list<Mana>::iterator Next = Cost.begin();
|Also, I'm not sure about the exact logic you intended for OrganizeCost(), but as written it only combines adjacent duplicates in the list, not over all entries.|
Cire is correct. I've sorted the list before this loop. So yes it will only combine adjacent elements, but since the list is sorted, this is fine.
So it seems there are two options for incrementing Next:
Next = Cost.erase(Next);
Are there any advantages to either one. There's no overhead differences really, except for the minimal space the copy of Next takes up, but since it's just and iterator, its pretty small. The second looks clearer to me, and works with vector - but honestly I don't see myself using vectors that much when list is so much more useful (then again, I don't do this for a living - yet!). Can anyone expound upon the strengths and weakness of each method?
P.S. Missed this earlier!
|¿how do you use that pointer?|
Sorry ne555, I missed this one. It's just an extra constructor I included because I'm OCD and I was testing it. I also have a reference constructor (for the copy constructor), a few others. I'd have to show you the whole class for them all to make sense though.