-
Notifications
You must be signed in to change notification settings - Fork 0
/
bag.py
31 lines (29 loc) · 667 Bytes
/
bag.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from dlist import DoubleList
class Bag:
def __init__(self):
self._list = DoubleList()
def contains(self, data):
return self._list.exists(data)
def insert(self, data):
self._list.insert(data)
def remove(self, data):
self._list.remove(data)
def clear(self):
self._list.clear()
def values(self):
return self._list.values()
if __name__ == '__main__':
b = Bag()
b.insert(1)
b.insert(2)
b.insert(3)
b.insert(4)
b.insert(2)
b.insert(3)
print(b.values())
b.remove(3)
print(b.values())
b.remove(2)
print(b.values())
b.remove(2)
print(b.values())