Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
reverse reverse
  • Loading branch information
clifhodges13 committed Jun 27, 2020
commit 53c4f84e1c703141c43cf7c1f6f23302b4a2e8b8
18 changes: 17 additions & 1 deletion reverse/reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ class LinkedList:
def __init__(self):
self.head = None

def __str__(self):
output = ''
current_node = self.head
while current_node is not None:
output += f'{current_node.value} > '
current_node = current_node.next_node
return output + 'None'

def add_to_head(self, value):
node = Node(value)

Expand All @@ -39,4 +47,12 @@ def contains(self, value):
return False

def reverse_list(self, node, prev):
pass
# we'll need to reference the previous node
# traverse the list and when we get to the end, that node will become the new head
current = self.head
while current is not None:
self.next_node = current.next_node
current.next_node = prev
prev = current
current = self.next_node
self.head = prev