File tree
Expand file treeCollapse file tree1 file changed
+17
-1
lines changed data_structures/LinkedList
Expand file treeCollapse file tree1 file changed
+17
-1
lines changed Original file line number | Diff line number | Diff line change |
---|
@@ -47,4 +47,20 @@ def delete_tail(Head):#delete from tail
|
47 | 47 | return Head
|
48 | 48 |
|
49 | 49 | def isEmpty(Head):
|
50 |
| -return Head is None #Return if Head is none |
| 50 | +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 |
You can’t perform that action at this time.
0 commit comments