Original
A one-way queue is similar to a stack where the stack is only adding or removing data at the top of the stack, and a one-way queue adds data from the end of the team and removes the data from the team header. The stack is advanced back-out (FILO), and the one-way queue is FIFO. In the STL, the one-way queue also uses other containers as the underlying data structure, by default using Deque, you can specify vectors and so on.
Queue common functions for one-way queues:
1. Data manipulation
Que.front ()
Returns a reference to the queue header data
Que.back ()
Returns a reference to the tail data of a queue
Que.push (Elem)
Add data at the end of the team
Que.pop ()
Queue head data out team
2. Other operations
Que.empty ()
Determines whether the queue is empty, or returns False if NULL returns TRUE.
Que.size ()
Returns the number of data in the queue
Queue one-way queues example:
#include <iostream>
#include <queue>
#include <vector>
using Std::queue;
Using Std::vector;
int main ()
{
queue<int> que;//uses deque as the underlying container
queue<int by default, vector<int> >quev;// Specifies that the vector is the underlying container for
(int i = 0; i < ++i)
{
que.push (i*i);
Quev.push (i);
}
Std::cout << "\ n" Team head Data: "<<que.front ();
Std::cout << "\ n \ nthe tail data:" << que.back ();
Std::cout << "\ n Queue Size:" << que.size ();
Std::cout << "\ n \ nthe data for queue que: \ n";
while (!que.empty ())
{
std::cout << que.front () << "";
Que.pop ();
}
System ("pause");
return 0;
}