Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

History

History
History
61 lines (46 loc) 路 1.73 KB

File metadata and controls

61 lines (46 loc) 路 1.73 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
'''
QUEUE
FIFO
# All Enqueue and Dequeue operations are to/from the top of the stack, i.e., last modified elements
Enqueue add an item to the end of the line
Dequeue remove an item from the front of the line
Enqueue from the one end and Dequeue from the another
QUEUE USE CASE
Bank Tellers, Placing an order at restaurent, SuperMarket CheckOut
#
append()
to enqueue an item to RightSide
appendleft()
to enqueue an item to LeftSide
pop()
to delete an item from RightSide
popleft()
to dequeue an item off the queue from the LeftSide
index(ele, beg, end)
returns first index of value mentioned in arguments from starting to end.
insert(i, a)
inserts value mentioned in arguments(a) at index(i) specified in arguments.
remove()
removes first occurrence of value mentioned in arguments.
count()
counts number of occurrences of value mentioned in arguments.
'''
''' CLASS QUEUE() '''
''' CLASS QUEUE() END '''
from collections import deque
queue = deque()
queue.append(5)
queue.append(4)
queue.append(3)
queue.append(2)
queue.append('A')
print(f"Queue is {queue}", end="\n\n")
queue.popleft()
print(f"Popping FIRST item {queue}", end="\n\n")
# insert(), index(), remove(), count()
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
queue.insert(3,1) # insert(index,val)
print (f"Queue after inserting 1 at index3 {queue}", end="\n\n")
print (f"1 has been repeated {queue.count(1)} times", end="\n\n")
queue.remove(3)
print (f"Deleting first occurrence of 3 is{queue}", end="\n\n")
Morty Proxy This is a proxified and sanitized view of the page, visit original site.