2 Comments

Hi Simon,

Can you explain what happens at the OOPS ? I didnt quite follow that.

Great content by the way, learning new stuff every day!

Expand full comment

This depends on the implementation of the algorithm. However, what a typical implementation will do is that it will move the not erased elements. This means that once we get past the first "2", the first element will be "2", meaning that we erase the second two and then not erase the "1".

Part of the problem is that the element to be erased is passed as reference, which is the correct choice, since you don't want to do expensive copies. But when you change the value of the element that you passed by reference, things go haywire.

Expand full comment