@@ -11,6 +11,7 @@ def __init__(self, value, prev=None, next=None):
1111 """Wrap the given value in a ListNode and insert it
1212 after this node. Note that this node could already
1313 have a next node it is point to."""
14+
1415 def insert_after (self , value ):
1516 current_next = self .next
1617 self .next = ListNode (value , self , current_next )
@@ -20,6 +21,7 @@ def insert_after(self, value):
2021 """Wrap the given value in a ListNode and insert it
2122 before this node. Note that this node could already
2223 have a previous node it is point to."""
24+
2325 def insert_before (self , value ):
2426 current_prev = self .prev
2527 self .prev = ListNode (value , current_prev , self )
@@ -28,6 +30,7 @@ def insert_before(self, value):
2830
2931 """Rearranges this ListNode's previous and next pointers
3032 accordingly, effectively deleting this ListNode."""
33+
3134 def delete (self ):
3235 if self .prev :
3336 self .prev .next = self .next
@@ -51,6 +54,7 @@ def __len__(self):
5154 """Wraps the given value in a ListNode and inserts it
5255 as the new head of the list. Don't forget to handle
5356 the old head node's previous pointer accordingly."""
57+
5458 def add_to_head (self , value ):
5559 new_node = ListNode (value , None , None )
5660 self .length += 1
@@ -65,6 +69,7 @@ def add_to_head(self, value):
6569 """Removes the List's current head node, making the
6670 current head's next node the new head of the List.
6771 Returns the value of the removed Node."""
72+
6873 def remove_from_head (self ):
6974 value = self .head .value
7075 self .delete (self .head )
@@ -73,6 +78,7 @@ def remove_from_head(self):
7378 """Wraps the given value in a ListNode and inserts it
7479 as the new tail of the list. Don't forget to handle
7580 the old tail node's next pointer accordingly."""
81+
7682 def add_to_tail (self , value ):
7783 new_node = ListNode (value , None , None )
7884 self .length += 1
@@ -87,13 +93,15 @@ def add_to_tail(self, value):
8793 """Removes the List's current tail node, making the
8894 current tail's previous node the new tail of the List.
8995 Returns the value of the removed Node."""
96+
9097 def remove_from_tail (self ):
9198 value = self .tail .value
9299 self .delete (self .tail )
93100 return value
94101
95102 """Removes the input node from its current spot in the
96103 List and inserts it as the new head node of the List."""
104+
97105 def move_to_front (self , node ):
98106 if node is self .head :
99107 return
@@ -103,6 +111,7 @@ def move_to_front(self, node):
103111
104112 """Removes the input node from its current spot in the
105113 List and inserts it as the new tail node of the List."""
114+
106115 def move_to_end (self , node ):
107116 if node is self .tail :
108117 return
@@ -112,6 +121,7 @@ def move_to_end(self, node):
112121
113122 """Removes a node from the list and handles cases where
114123 the node was the head or the tail"""
124+
115125 def delete (self , node ):
116126 self .length -= 1
117127 if self .head is self .tail :
@@ -127,6 +137,7 @@ def delete(self, node):
127137 node .delete ()
128138
129139 """Returns the highest value currently in the list"""
140+
130141 def get_max (self ):
131142 max_value = self .head .value
132143 current = self .head
@@ -135,4 +146,4 @@ def get_max(self):
135146 max_value = current .value
136147 current = current .next
137148
138- return max_value
149+ return max_value
0 commit comments