08 Queue and its applications


- A queue is another special type of list, where the elements are
- Inserted only at the rear of the list
- Deleted only at the front of the list
- Queue is often called FIFO (First-In First-Out) structure
- ไม่เหมือนกับ 07 Stack and its Applications นะ เพราะอันนี้คือ LIFO
Queue Operations
enqueue: Insert an element at the rear of the queue- Returns
trueif the operation was successful.
- Returns
dequeue: Remove the element at the front of the queue and return it.queueFrontget the value at the front of the queuequeueRearget the value at the rear of the queue
Application of Queues
- Prefix expression evaluation
- Round Robin scheduling
Prefix Expression
Related
- Expression that the operator comes before two operands
Ex. + 5 6
– * 4 3 + 1 1 - Prefix Expression is parenthesis-free
- เลื่อนอันข้างไปหลัง Queue เรื่อย ๆ จนกว่า 3 อันข้างหน้าจะได้เป็น (1) Operator (2,3) Operand
- สุดท้ายจะได้เลขออกมา 1 ตัว
Round Robin Scheduler
Related
- A round-robin scheduler is used to fairly allocate a limited resource that must be shared with a larger demand of users.
- It gives each process a unit of time, then moves to the next process, continues until all processes completed