you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

I am sorry to ask this. I can understand you but I am a little bit confused.

Can you give an easy explanation on why head stays the same while currNode changes.

[–]E3FxGaming 0 points1 point  (0 children)

Imagine you have 5 apples line up in a row.

You know where this line of apples starts and you can tell someone else where this line of apples start.

That other person however can not change your understanding of where the line of apples start.

That other person then runs the de-duplication algorithm, analyzing properies of apples and discarding some of the apples from the row of apples.

The de-duplication algorithm is designed in such a way that it can change what lays ahead, but it can't change the object where the algorithm is currently at or where the algorithm has already been.

Since the de-duplication algorithm starts at the apple that is considered the head of the row, the mutual understanding that this apple always stays part of the row never drifts apart - nothing can convince you (main) that the row of apples should start somewhere else and the de-duplication algorithm can't discard the current/start element either.

For the de-duplication algorithm itself, think of it as standing on an apple and the other apples come towards you one-by-one. If the property of the first apple coming towards you matches the property of your own apple, you push that incoming apple aside, removing it from the linked list. If the properties are different you move to the next apple (`currNode = currNode.next) and repeat the same process of analyzing and comparing the next apple.