-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.py
39 lines (35 loc) · 873 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
38
39
class Queue:
def __init__(self):
self.queue = []
def isEmpty(self):
if self.queue ==[]:
print("Queue is Empty")
else:
print("Queue is not empty")
def enqueue(self,element):
self.queue.insert(0,element)
def dequeue(self):
self.queue.pop()
def size(self):
print("size of queue is",len(self.queue))
#Code Execution
q=Queue()
q.isEmpty()
#insterting elements
print("instering element no.1")
q.enqueue("apple")
print("instering element no.2")
q.enqueue("banana")
print("insterting element no.3")
q.enqueue("orange")
print("the queue elements are as follows:")
print(q.queue)
print("check if queue is empty?")
q.isEmpty()
#removing elemnts
print("remove first element")
q.dequeue()
print("what is the size of the queue?")
q.size()
print("print contents of the queue")
print(q.queue)