queues are a type of container adaptor(容器适配器), specifically designed to operate in aFIFO context (first-in first-out), where elements are inserted into one end of the container and extracted from the other.
==============================================================
要将数据加进queue时,只要用q.push(item)即可,但要取出数据时,并不是用q.pop(),而是用q.front()取出最前面的数据,但数据依然存在;q.pop()则是将最前面的数据取出queue,其回传值为void。
一个栗子:
void testSTLQueue()
{
queue<string> stringQueue;
stringQueue.push("These ");
stringQueue.push("are ");
stringQueue.push("more ");
cout<<stringQueue.front();
stringQueue.pop();
cout<<stringQueue.front();
stringQueue.pop();
stringQueue.push("four ");
stringQueue.push("words!");
stringQueue.pop();
cout<<stringQueue.front();
stringQueue.pop();
cout<<stringQueue.front();
stringQueue.pop();
}
输出结果是:There are four words!
核心接口:
1.push()
2.front()
3.back()
Returns a reference to the last element in thequeue. This is the "newest" element in the queue
4.pop()
5.size()
6.empty()
bool empty() const;//Test whether container is empty
7.comparision(const queue& q1,const queue& q2)//两个同型queue的比较,
comparision可以是:==,!=,<,>,<=,>=
(如果两个queue的size()相等并且对应元素也相等则它们相等;比较基于字典序,参考lexicographical_compare())