C + + STL deque detailed

Source: Internet
Author: User

Deque container

The Deque container is the content in C + + STL. Deque is similar to vectors and supports random access and quick insert deletions. Deque also supports adding data from the start: Push_front ()

constructor function
deque<Elem> d;//创建一个空的dequedeque<Elem> d1(d2);//复制一个deque~deque<Elem>();//销毁所有数据,释放内存
member functions
deque.begin();//返回指向第一个元素的迭代器deque.end();//返回指向最后一个元素下一个位置的迭代器deque.rbegin();deque.rend();//反向迭代器
#include <cstdio>#include <deque>using namespace STD;intMain () { deque<int>D D.push_back (1);d. Push_front (2); deque<int>:: Iterator it; for(it = D.begin (); It! = D.end (); it + +) {printf("%d\n", *it); }//Output 2 1    return 0;}
d.at(pos);//返回索引为pos的位置的元素d[pos];//或者直接这样
 deque     <int ;  D;    D.push_back (1 );d. Push_front (2 ); printf  ( "%d\n" , d.at (1 ));    //output 1  printf  ( "%d\n" , D[1 ]); //output 1   
deque.empty();//判断deque是否空deque.front();//返回第一个元素deque.back();//返回最后一个元素deque.size();//返回容器大小deque.clear();//清除deque
Inserting and deleting
deque.erase(pos);//删除pos位置的元素deque.push_back(num);//在末尾插入元素deque.pop_back();//弹出末尾的元素deque.pop_front();//删除开头位置的元素

C + + STL deque detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.