fix 3.8_08

This commit is contained in:
Dmitry Belyaev 2024-04-16 13:18:11 +03:00
parent 0d65b8a938
commit aa5cfa0124

View File

@ -94,6 +94,22 @@ class Stack:
else: else:
self.bottom.next = obj self.bottom.next = obj
def pop(self) -> StackObj:
if not self.top:
return None
a, b, c = [self.top] + [None] * 2
while a:
a, b, c = a.next, a, b
if c:
c.next = None
if self.top in [b, c]:
self.top = None
return b
def __len__(self): def __len__(self):
count, obj = 0, self.top count, obj = 0, self.top
while obj: while obj:
@ -128,22 +144,6 @@ class Stack:
else: else:
self.top = value self.top = value
def pop(self) -> StackObj:
if not self.top:
return None
a, b, c = [self.top] + [None] * 2
while a:
a, b, c = a.next, a, b
if c:
c.next = None
if self.top in [b, c]:
self.top = None
return b
def get_data(self) -> List[StackObj]: def get_data(self) -> List[StackObj]:
return [x for x in self] return [x for x in self]
@ -151,7 +151,7 @@ class Stack:
return f"{self.__class__.__name__}({self.get_data()!r})" return f"{self.__class__.__name__}({self.get_data()!r})"
def __str__(self): def __str__(self):
return " -> ".join(self.get_data()) return " -> ".join(map(str, self.get_data()))
def tests(): def tests():