Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing the last element from a LinkedList is unnecessarily slow #19

Open
tom-churchill opened this issue Jul 29, 2019 · 2 comments
Open

Comments

@tom-churchill
Copy link

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

@sarah27h
Copy link

sarah27h commented Sep 1, 2019

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?

@parhamsaremi
Copy link

parhamsaremi commented Dec 20, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants