Exemplo n.º 1
0
 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())
Exemplo n.º 2
0
 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())
Exemplo n.º 3
0
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__()