In-depth analysis of the use of deque in C ++

Source: Internet
Author: User

First, when considering the memory allocation and execution performance, it is better to use std: deque than std: vector.

Deque Overview

Deque and vector are both in the standard template library. deque is a dual-end queue, which is very similar to vector in the interface and can be directly replaced in many operations. If the reader has been able to effectively use the vector container, the following section provides deque member functions and operations for comparative reference.

Function Description
C. assign (beg, end)
C. assign (n, elem)
Assign the value of the data in the [beg; end) interval to c.
Assign a copy of n elem values to c.
C. at (idx) Returns the data indicated by the index idx. If idx is out of bounds, out_of_range is thrown.
C. back () Returns the last data and does not check whether the data exists.
C. begin () Return the unique data of the iterator.
C. clear () Remove all data from the container.
Deque <Elem> c
Deque <Elem> c1 (c2)
Deque <Elem> c (n)
Deque <Elem> c (n, elem)
Deque <Elem> c (beg, end)
C .~ Deque <Elem> ()
Create an empty deque.
Copy A deque.
Create a deque that contains n pieces of data, which are created by default.
Create a deque that contains n elem copies.
Create a deque in the [beg; end) interval.
Destroys all data and releases memory.
C. empty () Determines whether the container is empty.
C. end () Point to the last data address in the iterator.
C. erase (pos)
C. erase (beg, end)
Delete the data at the pos position and return the location of the next data.
Delete the data in the [beg, end) interval and return the location of the next data.
C. front () Return a data record.
Get_allocator Returns a copy using the constructor.
C. insert (pos, elem)
C. insert (pos, n, elem)
C. insert (pos, beg, end)
Insert an elem copy at the pos position and return the new data location.
Insert more than n elem data at the pos position. No return value.
Data inserted in the [beg, end) range at the pos position. No return value.
C. max_size () Returns the maximum number of data in the container.
C. pop_back () Delete the last data.
C. pop_front () Delete the header data.
C. push_back (elem) Add a data entry to the end.
C. push_front (elem) Insert a data entry in the header.
C. rbegin () Returns the first data of a reverse queue.
C. rend () Returns the next location of the last data in a reverse queue.
C. resize (num) Specify the length of the queue again.
C. size () Returns the actual number of data in the container.
C1.swap (c2)
Swap (c1, c2)
SWAps c1 and c2 elements.
Same as above.

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.