STL系列之三 queue 單向佇列
阿新 • • 發佈:2018-12-20
//VS2008中 queue的定義 MoreWindows整理(http://blog.csdn.net/MoreWindows)template<class _Ty, class _Container = deque<_Ty> >class queue{ // FIFO queue implemented with a containerpublic: typedef _Container container_type; typedef typename _Container::value_type value_type; typedef typename _Container::size_type size_type; typedef typename _Container::reference reference; typedef typename _Container::const_reference const_reference; queue() : c() { // construct with empty container } explicit queue(const _Container& _Cont) : c(_Cont) { // construct by copying specified container } bool empty() const { // test if queue is empty return (c.empty()); } size_type size() const { // return length of queue return (c.size()); } reference front() { // return first element of mutable queue return (c.front()); } const_reference front() const { // return first element of nonmutable queue return (c.front()); } reference back() { // return last element of mutable queue return (c.back()); } const_reference back() const { // return last element of nonmutable queue return (c.back()); } void push(const value_type& _Val) { // insert element at beginning c.push_back(_Val); } void pop() { // erase element at end c.pop_front(); } const _Container& _Get_container() const { // get reference to container return (c); }protected: _Container c; // the underlying container};