Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
corrected the remove function to handle the case where the user inputs a value that is not in the list into the function
  • Loading branch information
wesleywu20 committed Mar 11, 2020
1 parent 52f53e0 commit 6f25d07
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 42 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added _sources/.DS_Store
Binary file not shown.
87 changes: 45 additions & 42 deletions _sources/BasicDS/ImplementinganUnorderedListLinkedLists.rst
Original file line number Diff line number Diff line change
Expand Up @@ -564,20 +564,21 @@ You can try out the ``UnorderedList`` class in ActiveCode 1.
return found

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

if previous == None:
self.head = current.getNext()
else:
previous.setNext(current.getNext())
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())

mylist = UnorderedList()

Expand Down Expand Up @@ -670,20 +671,21 @@ starting with 0.
return found

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

if previous == None:
self.head = current.getNext()
else:
previous.setNext(current.getNext())
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())

mylist = UnorderedList()

Expand Down Expand Up @@ -746,20 +748,21 @@ starting with 0.
return found

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

if previous == None:
self.head = current.getNext()
else:
previous.setNext(current.getNext())
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())

mylist = UnorderedList()

Expand Down
1 change: 1 addition & 0 deletions build_info
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0.0-37-g52f53e0

0 comments on commit 6f25d07

Please sign in to comment.