mauriciosantos/Buckets-JS

Removing the last element from a LinkedList is unnecessarily slow

tom-churchill opened this issue · 2 comments

Removing the first element from a LinkedList is fast, however, removing the last element is slow.

The problem seems to be that in the removeElementAtIndex function rather than simply accessing the lastNode element, the nodeAtIndex is called, fetching the second to last element, which is done by iterating over the entire list.

Removing the last element from a LinkedList is very common, so it being crippled severely hampers the usability of the data structure.

Thanks

Hi @tom-churchill,

I faced the same issue while I was implementing the removeLastNode method for LinkedList, Do you find another solution for this problem?

#23
i tried to remove the redundant line and fix the function