class LinkedListStack(Stack): def __init__(self): self._list = LinkedList() def get_size(self): return self._list.get_size() def is_empty(self): return self._list.is_empty() def push(self, e): self._list.add_first(e) def pop(self): return self._list.remove_first() def peek(self): return self._list.get_first() def __str__(self): cur = self._list._dummyhead.next res = [] while cur: res.append(str(cur.e)) cur = cur.next return "LinkedListStack : (Top) " + "->".join(res)
class LinkedListSet(Set): def __init__(self): self._list = LinkedList() def getSize(self): return self._list.get_size() def isEmpty(self): return self.isEmpty() def contains(self, e): return self._list.contains(e) def add(self, e): if self.contains(e): return self._list.add_first(e) def remove(self, e): self._list.remove(e)