Update linked list challenge (#124)

Remove extraneous check within the find method.  Clean up delete method.
This commit is contained in:
Donne Martin 2016-11-27 08:43:48 -05:00 committed by GitHub
parent 08d86de559
commit 5977fc994d
2 changed files with 12 additions and 12 deletions

View File

@ -44,8 +44,6 @@ class LinkedList(object):
def find(self, data):
if data is None:
return None
if self.head is None:
return None
curr_node = self.head
while curr_node is not None:
if curr_node.data == data:
@ -58,13 +56,15 @@ class LinkedList(object):
return
if self.head is None:
return
if self.head.data == data:
self.head = None
return
prev_node = self.head
curr_node = prev_node.next
curr_node = self.head.next
while curr_node is not None:
if curr_node.data == data:
prev_node.next = curr_node.next
return
else:
prev_node = curr_node
curr_node = curr_node.next

View File

@ -231,8 +231,6 @@
" def find(self, data):\n",
" if data is None:\n",
" return None\n",
" if self.head is None:\n",
" return None\n",
" curr_node = self.head\n",
" while curr_node is not None:\n",
" if curr_node.data == data:\n",
@ -245,13 +243,15 @@
" return\n",
" if self.head is None:\n",
" return\n",
" if self.head.data == data:\n",
" self.head = None\n",
" return\n",
" prev_node = self.head\n",
" curr_node = prev_node.next\n",
" curr_node = self.head.next\n",
" while curr_node is not None:\n",
" if curr_node.data == data:\n",
" prev_node.next = curr_node.next\n",
" return\n",
" else:\n",
" prev_node = curr_node\n",
" curr_node = curr_node.next\n",
"\n",