📄 cpplist_details.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1st October 2002), see www.w3.org"> <title>C++ Lists</title> </head> <body bgcolor="#ffffff"> <table width="100%" bgcolor="#eeeeff"> <tr> <td><a href="index.html">cppreference.com</a> -> <a href="cpplist.html">C++ Lists</a> -> Details</td> </tr> </table> <h1>C++ Lists</h1> <hr> <h2><a name="assign">assign</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void assign( <a href="iterators.html">input_iterator</a> start, <a href="iterators.html">input_iterator</a> end ); void assign( size_type num, const <a href="containers.html">TYPE</a> &val );</pre> </td> </tr> </table> <p>The assign() function either sets the list to the sequence <i>start</i> to <i>end</i>, or assigns the list <i>num</i> elements of type <i>val</i>.</p> <i>Related topics:</i><br> <strong><a href="#insert">insert()</a>,</strong> <hr> <h2><a name="back">back</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> reference back();</pre> </td> </tr> </table> <p>The function back() returns a reference to the last element of the list.</p> <i>Related topics:</i><br> <strong><a href="#front">front()</a>, <a href="#pop_back">pop_back()</a>,</strong> <hr> <h2><a name="begin">begin</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> <a href="iterators.html">iterator</a> begin();</pre> </td> </tr> </table> <p>The function begin() returns an <a href="iterators.html">iterator</a> to the first element of the list. For example,</p><pre> // Create a list of characters list<char> charList; for( int i=0; i < 10; i++ ) charList.push_front( i + 65 ); // Display the list list<char>::iterator theIterator; for( theIterator = charList.begin(); theIterator != charList.end(); theIterator++ ) cout << *theIterator;</pre> <br> <br> <i>Related topics:</i><br> <strong><a href="#end">end()</a>,</strong> <hr> <h2><a name="clear">clear</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void clear();</pre> </td> </tr> </table> <p>The clear() function deletes all elements from the list.</p> <hr> <h2><a name="empty">empty</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> bool empty();</pre> </td> </tr> </table> <p>The function empty() returns <strong>true</strong> if the list is empty, and <strong>false</strong> otherwise. For example:</p><pre> list<int> the_list; for( int i = 0; i < 10; i++ ) the_list.push_back( i ); while( !the_list.empty() ) { cout << the_list.front() << endl; the_list.pop_front(); } </pre> <hr> <h2><a name="end">end</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> <a href="iterators.html">iterator</a> end();</pre> </td> </tr> </table> <p>The end() function returns an <a href="iterators.html">iterator</a> the the end of the list.</p> <i>Related topics:</i><br> <strong><a href="#begin">begin()</a>,</strong> <hr> <h2><a name="erase">erase</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> <a href="iterators.html">iterator</a> erase( <a href="iterators.html">iterator</a> pos ); <a href="iterators.html">iterator</a> erase( <a href="iterators.html">iterator</a> start, <a href="iterators.html">iterator</a> end );</pre> </td> </tr> </table> <p>The erase() function removes the element at location <i>pos</i>, or removes the elements between <i>start</i> and <i>end</i>. The return value is an <a href="iterators.html">iterator</a> to the element after the last element that we removed.</p> <hr> <h2><a name="front">front</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> reference front();</pre> </td> </tr> </table> <p>The function front() returns a reference to the first element of the list.</p><pre> list<int> the_list; for( int i = 0; i < 10; i++ ) the_list.push_back( i ); while( !the_list.empty() ) { cout << the_list.front() << endl; the_list.pop_front(); }</pre> <i>Related topics:</i><br> <strong><a href="#back">back()</a>,</strong> <hr> <h2><a name="get_allocator">get_allocator</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> allocator_type get_allocator();</pre> </td> </tr> </table> <p>The function get_allocator() returns the allocator for the list.</p> <hr> <h2><a name="insert">insert</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> <a href="iterators.html">iterator</a> insert( <a href="iterators.html">iterator</a> pos, const <a href="containers.html">TYPE</a> &val ); void insert( <a href="iterators.html">iterator</a> pos, size_type num, const <a href="containers.html">TYPE</a> &val ); void insert( <a href="iterators.html">iterator</a> pos, <a href="iterators.html">input_iterator</a> start, <a href="iterators.html">input_iterator</a> end );</pre> </td> </tr> </table> <p>The insert() function either inserts <i>val</i> before the element at <i>pos</i>, inserts <i>num</i> copies of <i>val</i> before the element at <i>pos</i>, or inserts the sequence denoted by <i>start</i> and <i>end</i> before the element at <i>pos</i>. The return value is an <a href= "iterators.html">iterator</a> to the inserted element.</p> <hr> <h2><a name="max_size">max_size</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> size_type max_size();</pre> </td> </tr> </table> <p>The function max_size() returns the maximum number of elements that the list can hold.</p> <hr> <h2><a name="merge">merge</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void merge( list &lst ); void merge( list &lst, Comp compfunction );</pre> </td> </tr> </table> <p>The function merge() merges the list with <i>lst</i>, producing a combined lists that is in order. If <i>compfunction</i> is specified, then it is used as the comparison function for the lists.</p> <hr> <h2><a name="pop_back">pop_back</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void pop_back();</pre> </td> </tr> </table> <p>The pop_back() function removes the last element of the list.</p> <i>Related topics:</i><br> <strong><a href="#pop_front">pop_front()</a>,</strong> <hr> <h2><a name="pop_front">pop_front</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void pop_front();</pre> </td> </tr> </table> <p>The function pop_front() removes the first element of the list.</p> <i>Related topics:</i><br> <strong><a href="#pop_back">pop_back()</a>,</strong> <hr> <h2><a name="push_back">push_back</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void push_back( const <a href="containers.html">TYPE</a> &val );</pre> </td> </tr> </table> <p>The push_back() function appends <i>val</i> to the end of the list. For example:</p><pre> list<int> the_list; for( int i = 0; i < 10; i++ ) the_list.push_back( i );</pre> <i>Related topics:</i><br> <strong><a href="#push_front">push_front()</a>,</strong> <hr> <h2><a name="push_front">push_front</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void push_front( const <a href="containers.html">TYPE</a> &val );</pre> </td> </tr> </table> <p>The push_front() function inserts <i>val</i> at the beginning of the list.</p> <i>Related topics:</i><br> <strong><a href="#push_back">push_back()</a>,</strong> <hr> <h2><a name="rbegin">rbegin</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> <a href="iterators.html">reverse_iterator</a> rbegin();</pre> </td> </tr> </table> <p>The function rbegin() returns a reverse <a href="iterators.html">iterator</a> to the end of the list.</p> <i>Related topics:</i><br> <strong><a href="#rend">rend()</a>,</strong> <hr> <h2><a name="remove">remove</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void remove( const <a href="containers.html">TYPE</a> &val );</pre> </td> </tr> </table> <p>The function remove() removes all elements that are equal to <i>val</i> from the list. For example,</p><pre> // Create a list that has the first 10 letters of the alphabet list<char> charList; for( int i=0; i < 10; i++ ) charList.push_front( i + 65 ); // Remove all instances of 'E' charList.remove( 'E' ); </pre> <br> <br> <hr> <h2><a name="remove_if">remove_if</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void remove_if( UnPred pr );</pre> </td> </tr> </table> <p>The remove_if() function removes all elements from the list for which the unary predicate <i>pr</i> is true.</p> <hr> <h2><a name="rend">rend</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> <a href="iterators.html">reverse_iterator</a> rend();</pre> </td> </tr> </table> <p>The function rend() returns a reverse <a href="iterators.html">iterator</a> to the end of the list.</p> <hr> <h2><a name="resize">resize</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void resize( size_type num, <a href="containers.html">TYPE</a> val );</pre> </td> </tr> </table> <p>The function resize() changes the size of the list to <i>num</i>. Any elements that are added as padding will have the value <i>val</i>.</p> <hr> <h2><a name="reverse">reverse</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void reverse();</pre> </td> </tr> </table> <p>The function reverse() reverses the list.</p> <hr> <h2><a name="size">size</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> size_type size();</pre> </td> </tr> </table> <p>The size() function returns the number of elements in the list.</p> <hr> <h2><a name="sort">sort</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void sort(); void sort( Comp compfunction );</pre> </td> </tr> </table> <p>The sort() function sorts the lists, optionally using <i>compfunction</i> as the comparison function to determine if an element is less than another.</p> <hr> <h2><a name="splice">splice</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void splice( <a href="iterators.html">iterator</a> pos, list<T,Allocator> &lst ); void splice( <a href="iterators.html">iterator</a> pos, list<T,Allocator> &lst, <a href="iterators.html">iterator</a> del ); void splice( <a href="iterators.html">iterator</a> pos, list<T,Allocator> &lst, <a href="iterators.html">iterator</a> start, <a href="iterators.html">iterator</a> end );</pre> </td> </tr> </table> <p>The splice() function inserts <i>lst</i> at location <i>pos</i>. If specified, the element(s) at <i>del</i> or from <i>start</i> to <i>end</i> are removed.</p> <hr> <h2><a name="swap">swap</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void swap( list &lst );</pre> </td> </tr> </table> <p>The swap() function exchanges the elements in <i>lst</i> with those in the current list.</p> <hr> <h2><a name="unique">unique</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> void unique(); void unique( BinPred pr );</pre> </td> </tr> </table> <p>The function unique() removes all duplicate elements from the list. If <i>pr</i> is specified, then it is used to determine uniqueness.</p> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -