Pages

(Discuss) Queues

mercredi 7 septembre 2016
A queue is a container that holds elements in a linear structure. New elements are added only at one end of the queue (called the back). The only element that can be removed from the queue (and the only one whose value is visible) is at the opposite end of the queue (called the front).

To use queues in your program, use the directive #include <queue>. Declare your queue like this:


queue<long> Q;

Here is what you need to know to use queues.

To check if the queue is empty Q.empty() returns true if the queue is empty and false otherwise.


To add an element to the back of the queue Q.push(e) inserts the value in e to the end of the queue.\

To see the value at the front of the queue Q.front() gives the value held at the head of the queue.


(Discuss) Queues

Aucun commentaire:

Enregistrer un commentaire