本着不重新发明轮子的原则,我很少手码快排和其他数据结构……基本都是拖STL出来用……
STL中还是有不少实用的数据结构的……set,bitset,priority_queue,queue,vector,map……
bitset
Via http://www.cplusplus.com/reference/bitset/bitset/
Member functions
- (constructor)
- Construct bitset (public member function )
- applicable operators
- Bitset operators (function )
Bit access
- operator[]
- Access bit (public member function )
- count
- Count bits set (public member function )
- size
- Return size (public member function )
- test
- Return bit value (public member function )
- any
- Test if any bit is set (public member function )
- none
- Test if no bit is set (public member function )
- all
- Test if all bits are set (public member function )
Bit operations
- set
- Set bits (public member function )
- reset
- Reset bits (public member function )
- flip
- Flip bits (public member function )
Bitset operations
- to_string
- Convert to string (public member function )
- to_ulong
- Convert to unsigned long integer (public member function )
- to_ullong
- Convert to unsigned long long (public member function )
在一些模拟中……bitset还是不错的……不过用处也不是很大……
priority_queue
Member functions
- (constructor)
- Construct priority queue (public member function )
- empty
- Test whether container is empty (public member function )
- size
- Return size (public member function )
- top
- Access top element (public member function )
- push
- Insert element (public member function )
- emplace
- Construct and insert element (public member function )
- pop
- Remove top element (public member function )
- swap
- Swap contents (public member function )
优先队列的用处就比较多了,据说优先队列优化dij秒爆SPFA[来源请求]……
只要定义了 operator< ,就可以用优先队列来做成大顶堆。小顶堆……要么改operator<,要么
priority_queue<T
, vector<
T
>, greater<
T
> >
queue
Member functions
- (constructor)
- Construct queue (public member function )
- empty
- Test whether container is empty (public member function )
- size
- Return size (public member function )
- front
- Access next element (public member function )
- back
- Access last element (public member function )
- push
- Insert element (public member function )
- emplace
- Construct and insert element (public member function )
- pop
- Remove next element (public member function )
- swap
- Swap contents (public member function )
有优先队列优化的dij,就有队列优化的Bellman-Ford……
vector
Member functions
- (constructor)
- Construct vector (public member function )
- (destructor)
- Vector destructor (public member function )
- operator=
- Assign content (public member function )
Iterators:
- begin
- Return iterator to beginning (public member function )
- end
- Return iterator to end (public member function )
- rbegin
- Return reverse iterator to reverse beginning (public member function )
- rend
- Return reverse iterator to reverse end (public member function )
- cbegin
- Return const_iterator to beginning (public member function )
- cend
- Return const_iterator to end (public member function )
- crbegin
- Return const_reverse_iterator to reverse beginning (public member function )
- crend
- Return const_reverse_iterator to reverse end (public member function )
Capacity:
- size
- Return size (public member function )
- max_size
- Return maximum size (public member function )
- resize
- Change size (public member function )
- capacity
- Return size of allocated storage capacity (public member function )
- empty
- Test whether vector is empty (public member function )
- reserve
- Request a change in capacity (public member function )
- shrink_to_fit
- Shrink to fit (public member function )
Element access:
- operator[]
- Access element (public member function )
- at
- Access element (public member function )
- front
- Access first element (public member function )
- back
- Access last element (public member function )
- data
- Access data (public member function )
Modifiers:
- assign
- Assign vector content (public member function )
- push_back
- Add element at the end (public member function )
- pop_back
- Delete last element (public member function )
- insert
- Insert elements (public member function )
- erase
- Erase elements (public member function )
- swap
- Swap content (public member function )
- clear
- Clear content (public member function )
- emplace
- Construct and insert element (public member function )
- emplace_back
- Construct and insert element at the end (public member function )
Allocator:
- get_allocator
- Get allocator (public member function )
vector是个好东西,妈妈再也不用担心我的内存!
数组开大了爆内存,开小了爆下标……WTF……
还用的着担心邻接表MLE?vector没有压力。
map
Member functions
- (constructor)
- Construct multimap (public member function )
- (destructor)
- Multimap destructor (public member function )
- operator=
- Copy container content (public member function )
Iterators:
- begin
- Return iterator to beginning (public member function )
- end
- Return iterator to end (public member function )
- rbegin
- Return reverse iterator to reverse beginning (public member function )
- rend
- Return reverse iterator to reverse end (public member function )
- cbegin
- Return const_iterator to beginning (public member function )
- cend
- Return const_iterator to end (public member function )
- crbegin
- Return const_reverse_iterator to reverse beginning (public member function )
- crend
- Return const_reverse_iterator to reverse end (public member function )
Capacity:
- empty
- Test whether container is empty (public member function )
- size
- Return container size (public member function )
- max_size
- Return maximum size (public member function )
Modifiers:
- insert
- Insert element (public member function )
- erase
- Erase elements (public member function )
- swap
- Swap content (public member function )
- clear
- Clear content (public member function )
- emplace
- Construct and insert element (public member function )
- emplace_hint
- Construct and insert element with hint (public member function )
Observers:
- key_comp
- Return key comparison object (public member function )
- value_comp
- Return value comparison object (public member function )
Operations:
- find
- Get iterator to element (public member function )
- count
- Count elements with a specific key (public member function )
- lower_bound
- Return iterator to lower bound (public member function )
- upper_bound
- Return iterator to upper bound (public member function )
- equal_range
- Get range of equal elements (public member function )
Allocator:
- get_allocator
- Get allocator (public member function )
map用在一些需要存储键值对的地方……在一些需要维护数据的地方用这个偷懒一下也不错……
别忘了multimap。