-
Notifications
You must be signed in to change notification settings - Fork 0
queue
Hamin Pyo edited this page Aug 23, 2021
·
1 revision
A data structure with limited location for insertion and deletion, as with stacks.
F.I.F.O ( First In First Out)
-
Head
: the first (the oldest) element in the queue
-
Tail
: the last element (the newest) in element in the queue
-
Enqueue
: add an element to the tail
-
Dequeue
: remove the head element
-
Peek
: look at the head element, but not removing it
: a queue that goes both ways
-> you can enqueue & dequeue from either end
-> kind of a generalized version of both stacks & queues since you could represent either of them with it!
from collections import deque
q = deque()
q.append([1,2,3])
q.append([4,5,6])
# Head μμ ( 리μ€νΈμμ pop(0) νλ κ² λ³΄λ€, deque λ₯Ό import ν΄μ popleft λ₯Ό μ°λκ² λΉ λ₯΄λ€.)
q.popleft()
print(q)
=> [4,5,6]- assign each element a numerical priority when you insert it into the queue
- remove the element with the highest priority when you dequeue
-> if the elements have the same priority, the oldest element is the one that gets dequeue first