Adding reverse() to singly-linked list

Updating singly-linked list to include a reverse method using the three-way shuffle method.
This commit is contained in:
Tony De La Nuez 2017-10-22 18:04:10 -05:00 committed by GitHub
parent 535cbb76a3
commit 226a0a4ad8

View File

@ -47,4 +47,20 @@ class Linked_List:
return Head
def isEmpty(Head):
return Head is None #Return if Head is none
return Head is None #Return if Head is none
def reverse(Head):
prev = None
current = Head
while(current):
# Store the current node's next node.
next_node = current.next
# Make the current node's next point backwards
current.next = prev
# Make the previous node be the current node
prev = current
# Make the current node the next node (to progress iteration)
current = next_node
# Return prev in order to put the head at the end
Head = prev