Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions LinkedList/LinkedList.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,62 @@ def __init__(self, payload):

"""
def add(self, payload):
#TODO: Implement this function
new_node = LinkedList(payload)
new_node.next = self.next
self.next = new_node


""" Remove - Remove the node from the list that equals query """
def remove(self, query):
#TODO: Implement this function
cur = self.next
next_cur = cur.next

if cur.pl == query:
self.next = cur.next
return True


while(cur.next != None):

if cur.pl == query:
cur.next = next_cur.next
return True
elif next_cur.pl == query and next_cur.next == None:
cur.next = None
return True

cur = cur.next
next_cur = cur.next

return False

""" Search - Search for query in the list.

If query is found, then the item that was added to the node, if it isn't
then False will be returned
"""
def search(self, query):
#TODO: Implement this function
cur = self.next
next_cur = cur.next

while(cur.next != query):
if cur.pl == query:
return cur.pl
elif next_cur.pl == query and next_cur.next == None:
return next_cur.pl

cur = cur.next
next_cur = cur.next
return False

""" isEmpty - Return True if the list is Empty, False otherwise

"""
def isEmpty(self):
#TODO: Implement this function


if self.next == None:
return True
else:
return False
""" Print a linked list """
def print_list(self):
i=0
Expand All @@ -43,7 +77,7 @@ def print_list(self):
print(i, ":", cur.pl)
i += 1
cur = cur.next

print(i, ":", cur.pl)

def init_list():
return LinkedList(None)
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-minimal
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ def test_linked_list(lst, nItems):


# Uncomment this function call when you're ready to test
# test_linked_list(lst, 10)
test_linked_list(lst, 10)