forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.py
37 lines (31 loc) · 811 Bytes
/
Queue.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
# Queue implementation using List in Python
class Queue :
def __init__(self):
self.items =[]
def print_queue(self):
print ("\nQueue: ", self.items)
print ("Length of Queue: ", len(self.items))
self.print_top()
def print_top(self):
try:
print ("Topmost element in the Queue: ", self.items[0], "\n")
except IndexError:
print ("Topmost element in the Queue: NULL\n")
def enqueue(self, item):
self.items.insert(0,item)
print ("Enqueued value: ", item)
def dequeue(self):
print ('Dequeued value: ',self.items.pop())
if __name__ == '__main__' :
q = Queue()
q.print_queue()
q.enqueue(10)
q.enqueue(20)
q.enqueue(30)
q.enqueue(40)
q.enqueue(50)
q.print_queue()
q.dequeue()
q.dequeue()
q.dequeue()
q.print_queue()