C + + STL deque container member functions

Source: Internet
Author: User

Deque is a two-way queue that can be deleted in the header or inserted at the end. The interior is not contiguous, and this is not the same as the vector. It is possible that the address of the 1th element and the 2nd element are not joined together. It is safe to use it iterators when using it.

This is the C + + 98 standard, not c++11. 11 standard new Add-on functions are not explained here. Most of the functions inside are tested before they come to the conclusion.

function ( iterator simplified to it below )

Describe

Void c.assign (it beg,it end)
Void c.assign (it  N, Element type   elem)  

copies [beg; end) is assigned to c Span style= "font-family: the song Body;" > section 2
will n elem assigned to c Span style= "font-family: the song Body;" >

Both functions empty the original container and assign a value. Iterator is c the same container type.

It c.at (int idx)

Returns the index idx refers to the data,idx starting from 0 , if idx is out of bounds, throws Out_of_range .

Reference C.back ()

Returns the last data without checking to see if the data exists. The only pass is not deleted. Note The return value differs from begin .

It C.begin ()

Returns the first data address in an iterator. Returns the address of the first 1 data, the iterator type .

Void C.clear ()

Removes all data from the container, is emptied, and then accesses the data inside to make an error.

Void C.empty ()

Determines whether the container is empty. The return value is type bool . Jorian trueifnull returns false.

It C.end ()

The address of the next data that points to the last data in the iterator, which has no elements and is paired with begin . Returns the same address as begin If the container is empty .

It c.erase (it pos)
It c.erase (it beg,it end)

Deletes data from the POS location and returns the location of the next data.
Delete the data from the [beg,end] interval and return to the location of the next data. the 2 parameter is the first address of the last element, that is, the address has elements.

Reference C.front ()

Returns the first data in the container without checking to see if the data exists. The only pass is not deleted.

C.get_allocator ()

Use the constructor to return a copy. This function does not know how to use,Windows is not quite the same. Prototype Allocator_type get_allocator () const;

It C.insert (it pos, element type Elem)
void C.insert (it pos,int n, element type Elem)
void C.insert (it pos,it beg,it end)

in pos elem element copy to return the new data location. Logically pos The elements are moving backwards.
in pos position insertion n a elem element.
in pos position inserted in [beg,end) , which is also part of the container." End There are no actual elements.

Int c.max_size ()

Returns how many elements can be accommodated in a container. Different types of deque, can accommodate a number of different.

Void C.pop_back ()

Delete the last data.

Void C.pop_front ()

Delete header data.

Void c.push_back (element type Elem)

Add a data to the trailer.

Void C.push_front (element type Elem)

Inserts a data into the head.

It C.rbegin ()

Returns the address of the first data in a reverse queue. Use these two to reverse the output.

It C.rend ()

Returns the address of the next location of the last data in a reverse queue.

Re-specify the number of elements for the queue to num 2 case: 1. num 2. num More than the actual element, the default value is populated after the actual element to adjust the number. (Section 2 elements are optional, Default value for this type if not,

Int c.size ()

Returns the number of elements currently stored in the container. ( This differs from max_size )

Void C1.swap (deuqe C2)
void swap (deque c1,deque C2)

Interchange elements in C1 and C2 ,C1 and C2 are the same type of deque.
function as above, this can be used directly.

Deque<elem> C
deque<elem> C1 (deque C2)
deque<elem> C (int n)
deque<elem> C (int n, type Elem)
Deque<elem> C (It beg,it end)
C.~deque<elem> ()

Create an emptydeque. Elemcan be forint,Charwait a lot of different types.
ToC2initialized toC1, which is equivalent to copying a copy of a queue。
Create adeque, containingNData , both data areInitialized by the default value at the time of creation.
Create a containingNaElemcopy ofdeque.
Create a[Beg;end]Interval ofdeque.
Destroys all data, frees up memory, butCYou can also continue to use it, except for the number of elements that contain0。

C + + STL deque container member functions

Related Article

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.