Skip to content

unordered_set

AstroM edited this page May 25, 2017 · 3 revisions

unordered_set<int> m(nums1.begin(), nums1.end());

Construct

` int main ()
{
std::unordered_setstd::string first; // empty
std::unordered_setstd::string second ( {"red","green","blue"} ); // init list
std::unordered_setstd::string third ( {"orange","pink","yellow"} ); // init list
std::unordered_setstd::string fourth ( second ); // copy
std::unordered_setstd::string fifth ( cmerge(third,fourth) ); // move
std::unordered_setstd::string sixth ( fifth.begin(), fifth.end() ); // range

std::cout << "sixth contains:";  
for (const std::string& x: sixth) std::cout << " " << x;  
std::cout << std::endl;  

return 0;  

} `
Possible output:
sixth contains: pink yellow red green orange blue

Capacity

empty,size,max_size
` int main ()
{
std::unordered_setstd::string myset;
std::cout << "0. size: " << myset.size() << std::endl;

myset = {"milk","potatoes","eggs"};  
std::cout << "1. size: " << myset.size() << std::endl;  

myset.insert ("pineapple");  
std::cout << "2. size: " << myset.size() << std::endl;  

myset.erase ("milk");  
std::cout << "3. size: " << myset.size() << std::endl;  

return 0;  

} `

Output:
0. size: 0

  1. size: 3
  2. size: 4
  3. size: 3

Iterators

begin, end, cbegin, cend

Element lookup

find, count, equal_range

Modifiers

emplace, insert, erase, clear, swap

Hash policy

reverse

STL
  标准STL序列容器
  * vector
  * string
  * deque
  * list
  标准STL Associative Container
  * set
  * multiset
  * map
  * multimap
  非标准关联容器
  * hash_set
  * hash_multiset
  * hash_map
  * hash_multimap
  * unordered_set
  * unordered_multiset
  * unordered_map
  标准非STL容器
  * array
  * stack
  * queue
  * hash_multimap
  数据结构的对比

笔记
  常用头文件
  用法注意
  位运算

常见面试题
  面试题词汇
  TopK
  5亿个int找中位数
  多线程-生产者消费者模式

Suggestion
  * Suggestion for job

Clone this wiki locally