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

Problem in active code of unordered list #32

Open
irunestone opened this issue Nov 4, 2016 · 1 comment
Open

Problem in active code of unordered list #32

irunestone opened this issue Nov 4, 2016 · 1 comment

Comments

@irunestone
Copy link

Error reported in course pythonds on page ImplementinganUnorderedListLinkedLists by user anonymous [email protected]
The Complete UnorderedList Class (unorderedlistcomplete)
This active code has error in the remove function.
When you supply to a value to remove function that is not in the list, it gives a syntax error.
The condition where current becomes equal to None is not handled. Maybe there should be message like "Not found"

@victor-ono
Copy link

Corrected function:

    def remove(self,item):
        current = self.head
        previous = None
        found = False
        while current and not found:
            if current.getData() == item:
                found = True
            else:
                previous = current
                current = current.getNext()

        if found:
            if previous == None:
                self.head = current.getNext()
            else:
                previous.setNext(current.getNext())

wesleywu20 added a commit to nnhsse201920/pythonds that referenced this issue Mar 11, 2020
corrected the remove function to handle the case where the user inputs a value that is not in the list into the function
wesleywu20 added a commit to nnhsse201920/pythonds that referenced this issue Mar 12, 2020
wesleywu20 added a commit to nnhsse201920/pythonds that referenced this issue Mar 12, 2020
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

2 participants