@@ -42,8 +42,8 @@ class _Node:
42
42
"""
43
43
44
44
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
47
47
48
48
class _Iterator :
49
49
"""
@@ -81,7 +81,7 @@ def __next__(self) -> Any:
81
81
# finished iterating
82
82
raise StopIteration
83
83
val = self ._cur .val
84
- self ._cur = self ._cur .next
84
+ self ._cur = self ._cur .next_node
85
85
86
86
return val
87
87
@@ -128,8 +128,8 @@ def append(self, val: Any) -> None:
128
128
self ._len = 1
129
129
else :
130
130
# connect nodes
131
- self ._back .next = node
132
- node .prev = self ._back
131
+ self ._back .next_node = node
132
+ node .prev_node = self ._back
133
133
self ._back = node # assign new back to the new node
134
134
135
135
self ._len += 1
@@ -170,8 +170,8 @@ def appendleft(self, val: Any) -> None:
170
170
self ._len = 1
171
171
else :
172
172
# connect nodes
173
- node .next = self ._front
174
- self ._front .prev = node
173
+ node .next_node = self ._front
174
+ self ._front .prev_node = node
175
175
self ._front = node # assign new front to the new node
176
176
177
177
self ._len += 1
@@ -264,10 +264,9 @@ def pop(self) -> Any:
264
264
assert not self .is_empty (), "Deque is empty."
265
265
266
266
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
271
270
272
271
self ._len -= 1
273
272
@@ -300,8 +299,8 @@ def popleft(self) -> Any:
300
299
assert not self .is_empty (), "Deque is empty."
301
300
302
301
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
305
304
306
305
self ._len -= 1
307
306
@@ -385,8 +384,8 @@ def __eq__(self, other: object) -> bool:
385
384
# compare every value
386
385
if me .val != oth .val :
387
386
return False
388
- me = me .next
389
- oth = oth .next
387
+ me = me .next_node
388
+ oth = oth .next_node
390
389
391
390
return True
392
391
@@ -424,7 +423,7 @@ def __repr__(self) -> str:
424
423
while aux is not None :
425
424
# append the values in a list to display
426
425
values_list .append (aux .val )
427
- aux = aux .next
426
+ aux = aux .next_node
428
427
429
428
return "[" + ", " .join (repr (val ) for val in values_list ) + "]"
430
429
0 commit comments