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
finished reverse
  • Loading branch information
mtruj013 committed Sep 11, 2020
commit 3847cfd52422c11c031fc5459c62d0abb45719b4
24 changes: 23 additions & 1 deletion reverse/reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,26 @@ def contains(self, value):
return False

def reverse_list(self, node, prev):
pass

current = self.head

# if its empty
if not current:
return

# while theres something after the head
while current.next_node:
# store the next node
temp = current.next_node
# switch positions
current.next_node = prev
# move along the line
prev = current
current = temp
# since theres nothing after the last current, set the next node to prev which is none
current.next_node = prev

self.head = current