@@ -42,8 +42,8 @@ class _Node:
4242 """
4343
4444 val : Any = None
45- next : Deque ._Node | None = None
46- prev : Deque ._Node | None = None
45+ next_node : Deque ._Node | None = None
46+ prev_node : Deque ._Node | None = None
4747
4848 class _Iterator :
4949 """
@@ -81,7 +81,7 @@ def __next__(self) -> Any:
8181 # finished iterating
8282 raise StopIteration
8383 val = self ._cur .val
84- self ._cur = self ._cur .next
84+ self ._cur = self ._cur .next_node
8585
8686 return val
8787
@@ -128,8 +128,8 @@ def append(self, val: Any) -> None:
128128 self ._len = 1
129129 else :
130130 # connect nodes
131- self ._back .next = node
132- node .prev = self ._back
131+ self ._back .next_node = node
132+ node .prev_node = self ._back
133133 self ._back = node # assign new back to the new node
134134
135135 self ._len += 1
@@ -170,8 +170,8 @@ def appendleft(self, val: Any) -> None:
170170 self ._len = 1
171171 else :
172172 # connect nodes
173- node .next = self ._front
174- self ._front .prev = node
173+ node .next_node = self ._front
174+ self ._front .prev_node = node
175175 self ._front = node # assign new front to the new node
176176
177177 self ._len += 1
@@ -264,10 +264,9 @@ def pop(self) -> Any:
264264 assert not self .is_empty (), "Deque is empty."
265265
266266 topop = self ._back
267- self ._back = self ._back .prev # set new back
268- self ._back .next = (
269- None # drop the last node - python will deallocate memory automatically
270- )
267+ self ._back = self ._back .prev_node # set new back
268+ # drop the last node - python will deallocate memory automatically
269+ self ._back .next_node = None
271270
272271 self ._len -= 1
273272
@@ -300,8 +299,8 @@ def popleft(self) -> Any:
300299 assert not self .is_empty (), "Deque is empty."
301300
302301 topop = self ._front
303- self ._front = self ._front .next # set new front and drop the first node
304- self ._front .prev = None
302+ self ._front = self ._front .next_node # set new front and drop the first node
303+ self ._front .prev_node = None
305304
306305 self ._len -= 1
307306
@@ -385,8 +384,8 @@ def __eq__(self, other: object) -> bool:
385384 # compare every value
386385 if me .val != oth .val :
387386 return False
388- me = me .next
389- oth = oth .next
387+ me = me .next_node
388+ oth = oth .next_node
390389
391390 return True
392391
@@ -424,7 +423,7 @@ def __repr__(self) -> str:
424423 while aux is not None :
425424 # append the values in a list to display
426425 values_list .append (aux .val )
427- aux = aux .next
426+ aux = aux .next_node
428427
429428 return "[" + ", " .join (repr (val ) for val in values_list ) + "]"
430429
0 commit comments