8.3 Queues

A queue is an abstract structure in which items are entered at one end and removed from the other end. This behavior is called FIFO, which stands for “first in, first out.” This ADT sounds like a waiting line in a bank or supermarket. Indeed, queues are used to simulate this type of situation. Insertions are made at the rear of the queue, and removals are made from the front of the queue.

Another way of stating the accessing behavior of a queue is to say that the item removed is the item that has been in the queue the longest time. Viewing a queue from this perspective is more abstract. Like the stack, the insert operation has no constraints; the entire FIFO behavior is specified in the removal operation. Unfortunately, there is no standard queue terminology relating to the insertion and deletion operations. Enqueue, Enque, Enq, Enter, and Insert are all names used for the insertion operation. Dequeue, Deque, Deq, Delete, and Remove are names used for the deletion operation.

Here is an algorithm that reads in data values and prints them in the order in which they were entered:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.161.116