-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeque_using_list.py
44 lines (35 loc) · 1 KB
/
Deque_using_list.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
class Deque:
def __init__(self):
self.items=[]
def is_empty(self):
if len(self.items)==0:
print("Empty Deque")
else:
print("Deque is not empty")
def insert_first(self,item):
self.items.insert(0,item)
def insert_rear(self,item):
self.items.insert(-1,item)
def delete_front(self):
if self.items==None:
raise IndexError("Empty Deque")
else:
self.items.pop(0)
def delete_rear(self):
if not self.items==None:
self.items.pop()
else:
raise IndexError("Empty Deque")
def get_front(self):
if not self.items==None:
return self.items[0]
else:
raise IndexError("Empty Deque")
def get_rear(self):
if not self.items==None:
return self.items[-1]
else:
raise IndexError("Empty Deque")
def size(self):
return len(self.items)
d=Deque()