File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Author: OMKAR PATHAK
2
+
3
+ class Deque (object ):
4
+ def __init__ (self , limit = 10 ):
5
+ self .queue = []
6
+ self .limit = limit
7
+
8
+ def __str__ (self ):
9
+ return ' ' .join ([str (i ) for i in self .queue ])
10
+
11
+ # check if queue is empty
12
+ def isEmpty (self ):
13
+ return len (self .queue ) <= 0
14
+
15
+ # check if queue is full
16
+ def isFull (self ):
17
+ return len (self .queue ) >= self .limit
18
+
19
+ # for inserting at rear
20
+ def insertRear (self , data ):
21
+ if self .isFull ():
22
+ return
23
+ else :
24
+ self .queue .insert (0 , data )
25
+
26
+ # for inserting at front end
27
+ def insertFront (self , data ):
28
+ if self .isFull ():
29
+ return
30
+ else :
31
+ self .queue .append (data )
32
+
33
+ # deleting from rear end
34
+ def deleteRear (self ):
35
+ if self .isEmpty ():
36
+ return
37
+ else :
38
+ return self .queue .pop (0 )
39
+
40
+ # deleting from front end
41
+ def deleteFront (self ):
42
+ if self .isFull ():
43
+ return
44
+ else :
45
+ return self .queue .pop ()
46
+
47
+ if __name__ == '__main__' :
48
+ myDeque = Deque ()
49
+ myDeque .insertFront (1 ) # 1
50
+ myDeque .insertRear (2 ) # 2 1
51
+ myDeque .insertFront (3 ) # 2 1 3
52
+ myDeque .insertRear (10 ) #10 2 1 3
53
+ print (myDeque )
54
+ myDeque .deleteRear () # 2 1 3
55
+ print (myDeque )
56
+ myDeque .deleteFront () # 2 1
57
+ print (myDeque )
You can’t perform that action at this time.
0 commit comments