C + + of Deque

Source: Internet
Author: User

Deque (including the header file #include<deque>) is made up of several contiguous spaces, and once it is necessary to add new space at the head or end of the deque, a fixed amount of contiguous space is configured to thread the head or tail of the deque. Deque's biggest task is to maintain the illusion of its overall continuity in these segmented contiguous spaces, and provide a random access interface.

As a matter of fact. A map is maintained inside the deque (note!) Not a map container in the STL) is a small contiguous space in which each element is a pointer to another (larger) area called a buffer, which is used to hold the data in the deque. As a result, deque randomly accesses and traverses data more slowly than vectors. It inserts an element for the first time and dynamically allocates 512 bytes of space by default, and when that 512 bytes of space is exhausted, it dynamically allocates its own additional 512-byte space, and then it is connected to the virtual. This design of deque makes it a much more complex architecture, algorithm, and iterator design than vector. Its random access and traversal performance is worse than vector.

Deque is an optimized basic sequence container for adding and deleting operations on both ends of a sequence. Usually consists of some independent blocks, the first chunk expands in some direction, and the last chunk expands toward the other side. It allows for faster random access, but it does not keep all objects in a contiguous block of memory like a vector, but multiple contiguous blocks of memory. And keep track of these blocks and the order in a mapping structure.

  

1 //Queue Declaration2deque<int>Q;3 4 //insert an element in front of5 Q.push_front ();6 7 //Insert an element to the back8 Q.push_back ();9 Ten //Delete the previous element One Q.pop_front (); A  - //remove one of the following elements - Q.pop_back (); the  - //Team Top Elements - Q.front (); -  + //Team Tail Elements -Q.back ();

C + + of Deque

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.