We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1aa3717 + 226a0a4 commit 6bdf4fcCopy full SHA for 6bdf4fc
data_structures/LinkedList/singly_LinkedList.py
@@ -47,4 +47,20 @@ def delete_tail(Head):#delete from tail
47
return Head
48
49
def isEmpty(Head):
50
- return Head is None #Return if Head is none
+ return Head is None #Return if Head is none
51
+
52
+ def reverse(Head):
53
+ prev = None
54
+ current = Head
55
56
+ while(current):
57
+ # Store the current node's next node.
58
+ next_node = current.next
59
+ # Make the current node's next point backwards
60
+ current.next = prev
61
+ # Make the previous node be the current node
62
+ prev = current
63
+ # Make the current node the next node (to progress iteration)
64
+ current = next_node
65
+ # Return prev in order to put the head at the end
66
+ Head = prev
0 commit comments