def test_linkedlist1(self): _list = LinkedListElements() self.assertTrue(_list.is_empty()) _list.add(1) self.assertEqual(1, _list.get_head()) self.assertFalse(_list.is_empty()) self.assertEqual(1, _list.remove())
def test_linkedlist2(self): _list = LinkedListElements() self.assertTrue(_list.is_empty()) _list.add(1) _list.add(2) _list.add(3) self.assertEqual(3, _list.get_head()) self.assertEqual(3, _list.remove()) self.assertEqual(2, _list.get_head())
class StackLinkedList(Stack[T]): def __init__(self): self.list = LinkedListElements() def push(self, item): self.list.add(item) def pop(self): return self.list.remove() def peek(self): return self.list.get_head() def is_empty(self) -> bool: return self.list.is_empty() def __print__(self): return self.list.__print__()