Queues
Queues
“A Queue is a special kind of list, where items
are inserted at one end (the rear) And
deleted at the other end (the front)”
Other Name:
 First In First Out (FIFO)
3
A
B
A
C
B
A
D
C
B
A
D
C
B
rear
front
rear
front
rear
front
rear
front
rear
front
First In First Out
Difference from Stack:
Insertion go at the end of the list, rather than
the beginning of the list.
Common Operations on Queues
(Queue ADT)
1. MAKENULL(Q): Makes Queue Q be an empty list.
2. FRONT(Q): Returns the first element on Queue Q.
3. ENQUEUE(x,Q): Inserts element x at the end of Queue Q.
4. DEQUEUE(Q): Deletes the first element of Q.
5. EMPTY(Q): Returns true if and only if Q is an empty queue.
Example:
Line of customers in a bank

Lec-12, 13 Quees First In First Out (FIFO)

  • 1.
  • 2.
    Queues “A Queue isa special kind of list, where items are inserted at one end (the rear) And deleted at the other end (the front)” Other Name:  First In First Out (FIFO)
  • 3.
    3 A B A C B A D C B A D C B rear front rear front rear front rear front rear front First In FirstOut Difference from Stack: Insertion go at the end of the list, rather than the beginning of the list.
  • 4.
    Common Operations onQueues (Queue ADT) 1. MAKENULL(Q): Makes Queue Q be an empty list. 2. FRONT(Q): Returns the first element on Queue Q. 3. ENQUEUE(x,Q): Inserts element x at the end of Queue Q. 4. DEQUEUE(Q): Deletes the first element of Q. 5. EMPTY(Q): Returns true if and only if Q is an empty queue. Example: Line of customers in a bank

Editor's Notes

  • #1 Visit: tshahab.blogspot.com
  • #2 Visit: tshahab.blogspot.com
  • #3 Visit: tshahab.blogspot.com