File tree Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Original file line number Diff line number Diff line change 11class Node :
2- def __init__ (self , value = None , next_node = None ):
2+ def __init__ (self , value = None , next = None ):
33 self .value = value
4- self .next_node = next_node
4+ self .next = next
55
66 def get_value (self ):
77 return self .value
88
99 def get_next (self ):
10- return self .next_node
10+ return self .next
1111
1212 def set_next (self , new_next ):
13- self .next_node = new_next
13+ self .next = new_next
14+
1415
1516class LinkedList :
1617 def __init__ (self ):
@@ -39,4 +40,20 @@ def contains(self, value):
3940 return False
4041
4142 def reverse_list (self , node , prev ):
42- pass
43+ if self .head == None :
44+ return None
45+ # prev as none
46+ prev = None
47+ # current as head
48+ current = self .head
49+
50+ while current != None :
51+ # store the next node
52+ next = current .next
53+ # reverse the pointer to prev
54+ current .next = prev
55+ # move prev and current forward
56+ prev = current
57+ current = next
58+
59+ self .head = prev
You can’t perform that action at this time.
0 commit comments