C ++ primary container read the relevant section, it is necessary to summarize the main points of the container, a diagram illustrates.
Which, here are some of my ideas, please share.
Question 1. STL source code analysis · vector
Question 2. STL source code analysis · RB-tree
Question 3: unordered_map barrel growth law
Question 4:
#include<iostream> #include<vector> #include<map> using namespace std; int main() { cout << "iterator 访问vector " << endl; vector<int> vec = {1, 3, 5, 7, 9, 2, 4, 6, 8}; vector<int>::iterator it = vec.begin(); for(; it != vec.end(); ++it) cout << *it << " "; cout << "\niterator 访问map " << endl; map<string, string> mp = {{"chen", "zhang"}, {"yoci", "han"}}; auto p = mp.begin(); for(; p != mp.end(); ++p) cout << p->first << " " << p->second << endl; cout << "\niterator 访问复合map " << endl; map<string, vector<string>> mmp; for(int i=0; i<5; i++) { mmp.insert(pair<string, vector<string>>(to_string(i), {to_string(i*i), "这是测试时数据"})); } auto mmp_it = mmp.begin(); for(; mmp_it != mmp.end(); ++mmp_it) { cout << mmp_it->first << " - "; for(auto str : mmp_it->second) cout << str << " "; cout << endl; } return 0; }
概念性理解看这里:https://blog.csdn.net/u013719339/article/details/80615217