File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Queue implementation using Py List
2
+ # Enqueue and Dequeue TC is O(n), rest is O(1) as well as SC of all
3
+
4
+ class Queue :
5
+ def __init__ (self ):
6
+ self .list = []
7
+
8
+ def __str__ (self ):
9
+ values = [str (l ) for l in self .list ]
10
+ return ' ' .join (values )
11
+
12
+
13
+ def isEmpty (self ):
14
+ if self .list == []:
15
+ return True
16
+ else :
17
+ return False
18
+
19
+
20
+ # insert/push method
21
+ def enqueue (self , value ):
22
+ self .list .append (value )
23
+ return "Element inserted"
24
+
25
+
26
+ # remove/pop method
27
+ def dequeue (self ):
28
+ if self .isEmpty ():
29
+ return "Queue is empty"
30
+ else :
31
+ return self .list .pop (0 )
32
+
33
+
34
+ def peek (self ):
35
+ if self .isEmpty ():
36
+ return "Queue is empty"
37
+ else :
38
+ return self .list [0 ]
39
+
40
+
41
+ def delete (self ):
42
+ self .list = None
You can’t perform that action at this time.
0 commit comments