diff --git a/mod_oop/3.8_08_stack.py b/mod_oop/3.8_08_stack.py index 4047c01..baf4485 100644 --- a/mod_oop/3.8_08_stack.py +++ b/mod_oop/3.8_08_stack.py @@ -93,6 +93,22 @@ class Stack: self.top = obj else: 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): count, obj = 0, self.top @@ -128,22 +144,6 @@ class Stack: else: 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]: return [x for x in self] @@ -151,7 +151,7 @@ class Stack: return f"{self.__class__.__name__}({self.get_data()!r})" def __str__(self): - return " -> ".join(self.get_data()) + return " -> ".join(map(str, self.get_data())) def tests():