-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds_deque.py
56 lines (41 loc) · 1021 Bytes
/
ds_deque.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
class Deque(object):
"""Deque class.
It consists of 6 operations:
- add_front()
- add_rear()
- remove_front()
- remove_rear()
- is_empty()
- size()
"""
def __init__(self):
self.items = []
def add_front(self, item):
self.items.append(item)
def add_rear(self, item):
self.items.insert(0, item)
def remove_front(self):
return self.items.pop()
def remove_rear(self):
return self.items.pop(0)
def is_empty(self):
return self.items == []
def size(self):
return len(self.items)
def main():
d = Deque()
print(d.is_empty())
d.add_rear(4)
d.add_rear('dog')
d.add_front('cat')
d.add_front(True)
print(d.is_empty())
print(d.size())
d.add_rear(8.4)
print(d.remove_rear())
print(d.remove_front())
if __name__ == '__main__':
main()