File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Dequeue :
2
+ def __init__ (self ):
3
+ self .items = []
4
+
5
+ def is_empty (self ):
6
+ return self .items == []
7
+
8
+ def append (self , data ):
9
+ self .items .append (data )
10
+
11
+ def append_left (self , data ):
12
+ self .items .insert (0 , data )
13
+
14
+ def pop (self ):
15
+ return self .items .pop ()
16
+
17
+ def pop_left (self ):
18
+ return self .items .pop (0 )
19
+
20
+
21
+ q = Dequeue ()
22
+ print ('Menu' )
23
+ print ('append <value>' )
24
+ print ('appendleft <value>' )
25
+ print ('pop' )
26
+ print ('popleft' )
27
+ print ('quit' )
28
+
29
+ while True :
30
+ do = input ('What would you like to do? ' ).split ()
31
+
32
+ operation = do [0 ].strip ().lower ()
33
+ if operation == 'append' :
34
+ q .append (int (do [1 ]))
35
+ elif operation == 'appendleft' :
36
+ q .append_left (int (do [1 ]))
37
+ elif operation == 'pop' :
38
+ if q .is_empty ():
39
+ print ('Dequeue is empty.' )
40
+ else :
41
+ print ('Popped value from right: ' , q .pop ())
42
+ elif operation == 'popleft' :
43
+ if q .is_empty ():
44
+ print ('Dequeue is empty.' )
45
+ else :
46
+ print ('Popped value from left: ' , q .pop_left ())
47
+ elif operation == 'quit' :
48
+ break
You can’t perform that action at this time.
0 commit comments