7-DSA - Queue
7-DSA - Queue
Queue
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).
Middleware/Communication software
Hold messages/packets in order of their arrival
Messages are usually transmitted faster than the time to process them
The most common application is in client-server models
Multiple clients may be requesting services from one or more servers
Some clients may have to wait while the servers are busy
Those clients are placed in a queue and serviced in the order of arrival
Basic Operations
MAKENULL(Q)
Makes Queue Q be an empty list
FRONT(Q)
Returns the first element on Queue Q
ENQUEUE(x ,Q)
Inserts element x at the end of Queue Q
DEQUEUE(Q)
Deletes the first element of Q
EMPTY(Q)
Returns true if and only if Q is an empty queue
Enqueue And Dequeue Operations
Implementation
Static
Queue is implemented by an array
Size of queue remains fix
Dynamic
A queue can be implemented as a linked list
Expand or shrink with each enqueue or dequeue operation
Array Implementation
Use two counters that signify rear and front