queue
queue是模板类,定义在 < queue > 头文件里面。
template < class T, class Container = deque<T> > class queue;
T: Type of the elements.
Container: Type of the underlying container object used to store and access the elements.
T是元素的类型,container是容器类型,默认是deque类型。
定义一个int型的queue:
queue<int> q;
queue的基本函数:
push: 入队,将一个元素放在队列尾处 q.push(12)
pop:出队,弹出队列头部的元素即最先入队的元素,并不会返回被弹出的元素值 q.pop()
front:访问队列头部首元素,q.front() 返回最先入队的元素的值
back:访问队列尾部元素, q.back() 返回最后进入队列的元素
empty:判断队列是否为空 q.empty()
size: 查看队列中包含多少个元素 q.size() 返回队列中元素个数