""" stack.py a stack (first-in-last-out) implemented using a linked list $ python stack.py -- stack demo -- Push 1 onto the stack. Push 2 onto the stack. Push 3 onto the stack. Popping stack until empty : 3 2 1. Done. Jim Mahoney | cs.bennington.college | MIT License | March 2021 """ from linked_list import LinkedList, Node class Stack: def __init__(self): self._list = LinkedList() def is_empty(self): return self._list.is_empty() def push(self, value): self._list.push_end_value(value) def pop(self): return self._list.pop_end_value() def main(): print("-- stack demo --") stack = Stack() for i in range(1, 4): stack.push(i) print(f"Push {i} onto the stack.") print("Popping stack until empty : ", end='') while not stack.is_empty(): value = stack.pop() print(f" {value}", end='') print(".\nDone.") main()