-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQueue.py
More file actions
116 lines (85 loc) · 2.29 KB
/
Queue.py
File metadata and controls
116 lines (85 loc) · 2.29 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'''
#### Methods Available in Queue
Python provides the following methods, which are commonly used to perform the operation in Queue.
put(item) - This function is used to insert element to the queue.
get() - This function is used to extract the element from the queue.
empty() - This function is used to check whether a queue is empty or not. It returns true if queue is empty.
qsize - This function returns the length of the queue.
full() - If the queue is full returns true; otherwise false.
'''
'''Implementation Using List'''
print('-------------Implementation Using List--------------')
que = []
que.append('CSE')
que.append('EEE')
que.append('Civil')
que.append('ECE')
print(que)
print(que.pop(0))
print(que)
print(que.pop(0))
print(que)
print(que.pop(0))
print(que)
print(que.pop(0))
print(que)
'''Implementation Using List'''
print('--------------Implementation Using List----------------')
from collections import deque
q = deque()
q.append('ML')
q.append('DS')
q.append('Soft')
q.append('Networking')
print(q)
print(q.popleft())
print(q)
print(q.popleft())
print(q)
print(q.popleft())
print(q)
print(q.popleft())
print(q)
'''Implementation using queue.Queue'''
print('-------------Implementation using queue.Queue--------------')
from queue import Queue
qq = Queue(maxsize=4)
print(qq.qsize())
qq.put('a')
qq.put('b')
qq.put('c')
qq.put('d')
print(qq.full())
'''Queue Implementation'''
print('----------------Queue Implementation---------------')
# Implement Queue using List(Functions)
q=[]
def Enqueue():
if len(q)==size: # check wether the stack is full or not
print("Queue is Full!!!!")
else:
element=input("Enter the element:")
q.append(element)
print(element,"is added to the Queue!")
def dequeue():
if not q:# or if len(stack)==0
print("Queue is Empty!!!")
else:
e=q.pop(0)
print("element removed!!:",e)
def display():
print(q)
size=int(input("Enter the size of Queue:"))
while True:
print("Select the Operation:1.Add 2.Delete 3. Display 4. Quit")
choice=int(input())
if choice==1:
Enqueue()
elif choice==2:
dequeue()
elif choice==3:
display()
elif choice==4:
break
else:
print("Invalid Option!!!")