-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinked_List_Deque.py
54 lines (42 loc) · 1.31 KB
/
Linked_List_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
from Deque import Deque
from Linked_List import Linked_List
class Linked_List_Deque(Deque):
def __init__(self):
self.__list = Linked_List()
def __str__(self):
return str(self.__list)
def __len__(self):
return len(self.__list)
# DO NOT CHANGE ANYTHING ABOVE THIS LINE
def push_front(self, val):
# TODO replace pass with your implementation.
if len(self) == 0:
self.__list.append_element(val)
else:
self.__list.insert_element_at(val, 0)
def pop_front(self):
# TODO replace pass with your implementation.
if len(self) == 0:
return
return self.__list.remove_element_at(0)
def peek_front(self):
# TODO replace pass with your implementation.
if len(self) == 0:
return
return self.__list.get_element_at(0)
def push_back(self, val):
# TODO replace pass with your implementation.
self.__list.append_element(val)
def pop_back(self):
# TODO replace pass with your implementation.
if len(self) == 0:
return
return self.__list.remove_element_at(len(self) - 1)
def peek_back(self):
# TODO replace pass with your implementation.
if len(self) == 0:
return
return self.__list.get_element_at(len(self) - 1)
# Unit tests make the main section unneccessary.
#if __name__ == '__main__':
# pass