I am implementing an undo/redo buffer with generic LinkedList.
In this state:
[Top]
state4 (undone)
state3 (undone)
state2 <– current state
state1
[bottom]
When I do a Push, I would like to remove all states after the current one, and push the new one.
My current bypass is to do while (currentState != list.last), list.removeLast(); but it sucks
LinkedList just support Remove, RemoveFirst & removeLast…
I would like something like RemoveAllNodesAfter(LinkedListNode …) ?
How can I code that nicely, without iterating throught all nodes ? Maybe with extensions ?…
I can’t see anything in the standard
LinkedList<T>which lets you do this. You could look in PowerCollections and the C5 collections if you want – or just roll your ownLinkedListtype. It’s one of the simpler collections to implement, especially if you can add functionality in a ‘just in time’ manner.