Skip to content

Commit be6f44a

Browse files
committed
queue
1 parent 7e938e7 commit be6f44a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

DSA-Python/DataStructures/queue.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'''
2+
QUEUE
3+
FIFO
4+
5+
# All Enqueue and Dequeue operations are to/from the top of the stack, i.e., last modified elements
6+
Enqueue add an item to the end of the line
7+
Dequeue remove an item from the front of the line
8+
Enqueue from the one end and Dequeue from the another
9+
10+
QUEUE USE CASE
11+
Bank Tellers, Placing an order at restaurent, SuperMarket CheckOut
12+
#
13+
append()
14+
to enqueue an item to RightSide
15+
appendleft()
16+
to enqueue an item to LeftSide
17+
pop()
18+
to delete an item from RightSide
19+
popleft()
20+
to dequeue an item off the queue from the LeftSide
21+
index(ele, beg, end)
22+
returns first index of value mentioned in arguments from starting to end.
23+
insert(i, a)
24+
inserts value mentioned in arguments(a) at index(i) specified in arguments.
25+
remove()
26+
removes first occurrence of value mentioned in arguments.
27+
count()
28+
counts number of occurrences of value mentioned in arguments.
29+
'''
30+
31+
32+
''' CLASS QUEUE() '''
33+
34+
''' CLASS QUEUE() END '''
35+
36+
37+
from collections import deque
38+
queue = deque()
39+
queue.append(5)
40+
queue.append(4)
41+
queue.append(3)
42+
queue.append(2)
43+
queue.append('A')
44+
45+
print(f"Queue is {queue}", end="\n\n")
46+
47+
queue.popleft()
48+
print(f"Popping FIRST item {queue}", end="\n\n")
49+
50+
# insert(), index(), remove(), count()
51+
52+
print (f"Index of 2 between index 0&3 is {queue.index(3,1,4)}", end="\n\n") # index(ele, begi, endi) : return First repetitive_index of element
53+
54+
queue.insert(3,1) # insert(index,val)
55+
print (f"Queue after inserting 1 at index3 {queue}", end="\n\n")
56+
57+
print (f"1 has been repeated {queue.count(1)} times", end="\n\n")
58+
59+
queue.remove(3)
60+
print (f"Deleting first occurrence of 3 is{queue}", end="\n\n")
61+

0 commit comments

Comments
 (0)