📄 all.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <meta name="generator" content= "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"> <title>C++ Multisets</title> <link href="../cppreference.css" rel="stylesheet" type="text/css"></head><body><table> <tr> <td> <div class="body-content"> <div class="header-box"> <a href="../index.html">cppreference.com</a> > <a href= "index.html">C++ Multisets</a> </div> <div class="name-format"> begin </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <set> iterator begin(); const_iterator begin() const;</pre> <p>The function begin() returns an iterator to the first element of the multiset. begin() should run in <a href= "../complexity.html">constant time</a>.</p> <p>For example, the following code uses begin() to initialize an iterator that is used to traverse a list:</p> <pre class="example-code"> // 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> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="end.html">end</a><br> <a href="rbegin.html">rbegin</a><br> <a href="rend.html">rend</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> clear </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <set> void clear();</pre> <p>The function clear() deletes all of the elements in the multiset. clear() runs in <a href="../complexity.html">linear time</a>.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> (C++ Lists) <a href="../cpplist/erase.html">erase</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> Container constructors & destructors </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <set> container(); container( const container& c ); ~container();</pre> <p>Every multiset has a default constructor, copy constructor, and destructor.</p> <p>The default constructor takes no arguments, creates a new instance of that multiset, and runs in <a href="../complexity.html">constant time</a>. The default copy constructor runs in <a href= "../complexity.html">linear time</a> and can be used to create a new multiset that is a copy of the given multiset <em>c</em>.</p> <p>The default destructor is called when the multiset should be destroyed.</p> <p>For example, the following code creates a pointer to a vector of integers and then uses the default multiset constructor to allocate a memory for a new vector:</p> <pre class="example-code"> vector<int>* v; v = new vector<int>(); </pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> (C++ Strings) <a href="../cppstring/resize.html">resize</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> Container operators </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <set> container operator=(const container& c2); bool operator==(const container& c1, const container& c2); bool operator!=(const container& c1, const container& c2); bool operator<(const container& c1, const container& c2); bool operator>(const container& c1, const container& c2); bool operator<=(const container& c1, const container& c2); bool operator>=(const container& c1, const container& c2);</pre> <p>All of the C++ containers can be compared and assigned with the standard comparison operators: ==, !=, <=, >=, <, >, and =. Performing a comparison or assigning one multiset to another takes <a href="../complexity.html">linear time</a>.</p> <p>Two multisets are equal if:</p> <ol> <li>Their size is the same, and</li> <li>Each member in location i in one multiset is equal to the the member in location i in the other multiset.</li> </ol> <p>Comparisons among multisets are done lexicographically.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> (C++ Strings) <a href="../cppstring/string_operators.html">String operators</a><br> (C++ Strings) <a href="../cppstring/at.html">at</a><br> (C++ Lists) <a href="../cpplist/merge.html">merge</a><br> (C++ Lists) <a href="../cpplist/unique.html">unique</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> count </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <set> <strong>size_type</strong> count( const <a href="../containers.html">key_type</a>& key );</pre> <p>The function count() returns the number of occurrences of <em>key</em> in the multiset.</p> <p>count() should run in <a href="../complexity.html">logarithmic time</a>.</p> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> empty </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <set> bool empty() const;</pre> <p>The empty() function returns true if the multiset has no elements, false otherwise.</p> <p>For example, the following code uses empty() as the stopping condition on a (C/C++ Keywords) <a href= "../keywords/while.html">while</a> loop to clear a multiset and display its contents in reverse order:</p> <pre class="example-code"> vector<int> v; for( int i = 0; i < 5; i++ ) { v.push_back(i); } while( !v.empty() ) { cout << v.back() << endl; v.pop_back(); } </pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="size.html">size</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> end </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <set> iterator end(); const_iterator end() const;</pre> <p>The end() function returns an iterator just past the end of the multiset.</p> <p>Note that before you can access the last element of the multiset using an iterator that you get from a call to end(), you'll have to decrement the iterator first.</p> <p>For example, the following code uses <a href= "begin.html">begin</a>() and end() to iterate through all of the members of a vector:</p> <pre class="example-code"> vector<int> v1( 5, 789 ); vector<int>::iterator it; for( it = v1.begin(); it != v1.end(); it++ ) { cout << *it << endl; } </pre> <p>The iterator is initialized with a call to <a href= "begin.html">begin</a>(). After the body of the loop has been executed, the iterator is incremented and tested to see if it is equal to the result of calling end(). Since end() returns an iterator pointing to an element just after the last element of the vector, the loop will only stop once all of the elements of the vector have been displayed.</p> <p>end() runs in <a href="../complexity.html">constant time</a>.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="begin.html">begin</a><br> <a href="rbegin.html">rbegin</a><br> <a href="rend.html">rend</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> equal_range </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <set> pair<iterator, iterator> equal_range( const <a href="../containers.html">key_type</a>& key );</pre> <p>The function equal_range() returns two iterators - one to the first element that contains <em>key</em>, another to a point just after the last element that contains <em>key</em>.</p> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> erase </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <set> void erase( iterator pos ); void erase( iterator start, iterator end ); <strong>size_type</strong> erase( const <a href="../containers.html">key_type</a>& key );</pre> <p>The erase function() either erases the element at <em>pos</em>, erases the elements between <em>start</em> and <em>end</em>, or erases all elements that have the value of <em>key</em>.</p> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> find </div> <div class="syntax-name-format">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -