STL -- deque and list)

Source: Internet
Author: User

Double-end Queue (deque container class): # include <deque> is similar to vector. It supports random access and fast insertion and deletion. the operation on a specific position in the container takes linear time. Unlike vector, deque also supports data insertion from the start: push_front (). In addition, deque does not support operations similar to capacity () and reserve () of vector. Deque, short for "double-ended queue. Random Element access (direct access using indexes ). Adding or removing elements to or from the array header and tail is fast, but it takes a lot of time to add or remove elements in the central part.Header file # include <deque>Define the variable deque <int> mydeq;The main member function mydeq. clear () removes all data from the container. Mydeq. push_front (elem) adds a data mydeq to the queue header. pop_front () deletes the end data of the queue mydeq. push_back (elem) adds a data mydeq to the end of the queue. pop_back () deletes the end data of the queue mydeq. empty () determines whether the queue is empty. If it is null, truemydeq is returned. size () returns the actual number of data in the container. Mydeq. erase (pos) deletes the data at the pos position and returns the location of the next data. Mydeq. insert (pos, cnt, elem) inserts cnt data elem at the pos position. The pointer returned by mydeq. begin () points to the first data in the array. Mydeq. end () is actually to take the end and add one to make the loop run correctly-it returns the pointer to the data closest to the array boundary. Operator [] returns a reference deque in a specified position in the container. For example: <deque> <> put_deque (INTDEQUE deque, * cout <name <(pdeque = deque. begin (); pdeque! = Deque. end (); pdeque ++ <* pdeque <cout <INTDEQUE deq2 (, put_deque (deq1, put_deque (deq2, deq1.push _ back (<deq1.push _ front (<deq1.insert (deq1.begin () +, <cout <deq1.at () <deq1 [] <) =] = <deq1.erase (deq1.begin () + <deq2.assign (, <View Code linked list (list container class): # include <list> is a bilinear list that can only be accessed in sequence (from front to back or from back to front ). List data organization form <> <list> PrintIt (list <> (list <>:: iterator iter = n. begin (); iter! = N. end (); ++ <* iter <; main (<> listn1.push _ back (listn2.push _ back (<cout <

 

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.