STL之deque(双向队列)

deque双向队列是一种双向开口的连续线性空间,可以高效的在头尾两端插入和删除元素,deque在接口上和vector非常相似,下面列出deque的常用成员函数: deque在vector函数的基础上增加了一些函数,体现了双向队列的双向性 push_front() 在队列前插入一个元素 push_back() 在队列后插入一个元素 pop_back() 删除队尾元素 pop_front() 删除队首元素
#include
#include
#include
using namespace std ;
typedef deque Q ;
int main()  {
    Q q ;
    for(int i = 0 ; i < 10 ; i++)
        q.push_back(i) ;
    cout << q.front() << " ";
    cout << q.back() << endl ;
    cout << "size :" << q.size() << endl ;
    q.pop_front() ;
    cout << q.front() << " " ;
    cout << q.back() << endl ;
    cout << "size :" << q.size() << endl ;
    q.pop_back() ;
    cout << q.front() << " " ;
    cout << q.back() << endl ;
    cout << "size :" << q.size() << endl ;
    return 0 ;
}
posted @ 2014-10-20 13:16  NYNU_ACM  阅读(153)  评论(0编辑  收藏  举报