C + + STL library Common api--list__c++

Source: Internet
Author: User
Introduction to List

The list is a two-way linked list container that can efficiently insert deletion elements.
The list cannot have random access to elements, so it does not support at. (POS) functions and [] operators. before the list is ready for use

#include <list>  
using namespace std;
default construction of the list objectList using template class implementation, List object default construction form: List Lstt; such as: List<int> lstint; Defines a list container that holds int. List<float> lstfloat; Defines a list container that holds float.
*list<string> lststring; Defines a list container that holds a string.
...
You can also set pointer types or custom types within angle brackets. list-and-tail add removal operationList.push_back (Elem); Add an element to the tail of the container list.pop_back (); Deletes the last element in the container List.push_front (elem); Inserts an element List.pop_front () at the beginning of the container; Remove the first element from the beginning of a container data access for listList.front (); Returns the first element. List.back (); Returns the last element. List and iteratorList.begin (); Returns an iterator for the first element in a container. List.end (); Returns an iterator after the last element in a container. List.rbegin (); Returns the iterator of the penultimate element in the container. List.rend (); Returns the iterator behind the last element in the container. the construction of the list object with parametersList (beg,end); The constructor copies the elements in the [Beg, end] interval to itself. Note that the interval is left closed and right open. List (N,elem); The constructor copies n Elem to itself. List (const list &lst); Copy constructors. the assignment of the listList.assign (Beg,end); The copy of the data in the [Beg, end] interval is assigned to itself. Note that the interval is left closed and right open. List.assign (N,elem); Assigns n elem copies to itself. list& operator= (const list &lst); Overloaded equals operator List.swap (LST); Swap the LST with its own elements. the size of the listList.size (); Returns the number of elements in a container list.empty (); Determine whether the container is empty list.resize (num); Reassign the length of the container to NUM and, if the container becomes longer, fills the new location with the default value. If the container is shortened, the element at the end that exceeds the container length is deleted. List.resize (num, elem); Re-specify the length of the container to NUM and, if the container is longer, populate the new location with the Elem value. If the container is shortened, the element at the end that exceeds the container length is deleted. Insert of ListList.insert (Pos,elem); Inserts a copy of the Elem element at the POS location, returning the location of the new data. List.insert (Pos,n,elem); Inserts n elem data at the POS position with no return value. List.insert (Pos,beg,end); Inserts the data from the [beg,end) interval at the POS position without a return value. deletion of ListList.clear (); Remove all data from the container list.erase (beg,end); Deletes the data from the [beg,end) interval and returns the location of the next data. List.erase (POS); Deletes the data at the POS location and returns the location of the next data. Lst.remove (Elem); Deletes all elements in the container that match the Elem value. reverse order of listLst.reverse (); Reverse linked lists, such as LST containing 1,3,5 elements, after this method is run, LST contains 5,3,1 elements.

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.