STL – STL summary

6、 Deque

·#Include < deque > · double ended queue· Common interfaces: front(), back(); push_ back(),push_ front(); pop_ back(),pop_ front(); empty(),clear().

7、 BitSet

·#Include < BitSet > · binary array, each position can only be assigned 0 or 1· Common interfaces: [] BitSet output with cout is better

8、 Priority_ queue

·#Include < queue > · priority queue (heap)? This is useful. · common interface: top(); push(); pop(); empty(),size(); No clear ()

9、 Set

·#Include < set > · set· Common interfaces: insert(), erase(); find(); empty(),clear().

10、 Multiset

·#Include < set > · repeatable sets· Common interfaces: insert(), erase(); find(),count(); empty(),clear(). Note that erase () here will delete all the same things

11、 Map

·#Include < Map > · mapping· The elements in the map are of pair type· Common interfaces: insert(), erase(); find(); []; empty(),clear().

12、 Hash_ map

·I don't want to write my own hash. I don't recommend using C + + hash_ map. · hash_ Map is not a standard STL, so in cplusplus Not on it. Www. 68mn· Hash on Linux_ Map is__ gnu_ In cxx, and unordered_ Map is the data structure in c++11. Neither of these two can debug in the exam. 100% not recommended. If you really don't want / can write hash, please use map instead

13、 Iterator

·Each STL data structure has a corresponding iterator, which is called iterator in Chinese· For example, the iterator of set < int > is set < int >:: iterator, which is used to access the elements inside the data structure For example, set, multiset and map are internally ordered and can be accessed from small to large through iterators· The iterator itself is a pointer. To access the internal elements, use * or - >

14、 Lower_ bound(),upper_ bound()

·For a set, you can use lower_ Bound and upper_ Bound for binary query: · s.lower_ Bound (x) returns an iterator pointing to the smallest element greater than or equal to X. if there is no such element, it returns a random value· s.upper_ Bound (x) and s.lower_ Bound (x) is a meaning, the only difference is that there is no equal to· upper_ Bound is not less than!

15、 Caution

·Note: the data structure of STL is expensive, so we should always consider whether it is empty, otherwise it is easy to re· A typical example of Re: vector accesses out of bounds through subscript Access top () when stack is empty· Address out of bounds will not necessarily re, but it will still affect the normal operation of the program

16、 Algorithm

·There is also an algorithm library in STL. There are several easy to use algorithms Sort () sequence sorting; Reverse() sequence inversion; random_ Shuffle () sequence is disordered; next_ Permutation() generates the next permutation; Min(), max(), swap() takes the maximum and minimum value, and the two elements are exchanged

17、 Sort

·The more important function in algorithm is sort()· The utility is to sort a sequence from small to large Sort () is not a simple quick sort, but the time complexity is also o (nlogn) Sort () can sort arrays or vectors, but cannot sort other STL data structures The first parameter of sort () is the beginning of the array, and the second parameter is the last position at the end of the array Sort () has a third parameter, CMP

18、 Reverse

·This is relatively simple, which is to flip an array· Parameters are the same as sort. The first parameter is the beginning of the array and the second parameter is the last position at the end of the array

19、 Random_ shuffle

·This is also relatively simple, that is, to confuse the contents of an array· Parameters are the same as sort. The first parameter is the beginning of the array and the second parameter is the last position at the end of the array

20、 Next_ permutation

·This is also relatively simple, that is, to generate the next permutation of the current permutation (dictionary order meaning). · like sort, the first parameter is the beginning of the array, and the second parameter is the last position at the end of the array. · of course, there is also a function prev_permutation(), which is used to generate the previous permutation of the current permutation (dictionary order meaning)

·Note:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>