Loading docs/lang/csl/associative-container.md +18 −24 Original line number Diff line number Diff line Loading @@ -97,8 +97,7 @@ map<string, int> mp; ```cpp set<int> s; typedef set<int>::iterator si; for(si it=s.begin();it!=s.end();it++) cout<<*it<<endl; for (si it = s.begin(); it != s.end(); it++) cout << *it << endl; ``` 需要注意的是,对 `map` 的迭代器解引用后,得到的是类型为 `pair<Key, T>` 的键值对。 Loading @@ -107,8 +106,7 @@ for(si it=s.begin();it!=s.end();it++) ```cpp set<int> s; for(auto x:s) cout<<x<<endl; for (auto x : s) cout << x << endl; ``` 对于任意关联式容器,使用迭代器遍历容器的时间复杂度均为 $O(n)$ 。 Loading @@ -124,12 +122,8 @@ for(auto x:s) 例如,我们想要维护一个存储整数,且较大值靠前的 `set` ,可以这样实现: ```cpp struct cmp { bool operator()(int a,int b) { return a>b; } struct cmp { bool operator()(int a, int b) { return a > b; } }; set<int, cmp> s; ``` Loading Loading
docs/lang/csl/associative-container.md +18 −24 Original line number Diff line number Diff line Loading @@ -97,8 +97,7 @@ map<string, int> mp; ```cpp set<int> s; typedef set<int>::iterator si; for(si it=s.begin();it!=s.end();it++) cout<<*it<<endl; for (si it = s.begin(); it != s.end(); it++) cout << *it << endl; ``` 需要注意的是,对 `map` 的迭代器解引用后,得到的是类型为 `pair<Key, T>` 的键值对。 Loading @@ -107,8 +106,7 @@ for(si it=s.begin();it!=s.end();it++) ```cpp set<int> s; for(auto x:s) cout<<x<<endl; for (auto x : s) cout << x << endl; ``` 对于任意关联式容器,使用迭代器遍历容器的时间复杂度均为 $O(n)$ 。 Loading @@ -124,12 +122,8 @@ for(auto x:s) 例如,我们想要维护一个存储整数,且较大值靠前的 `set` ,可以这样实现: ```cpp struct cmp { bool operator()(int a,int b) { return a>b; } struct cmp { bool operator()(int a, int b) { return a > b; } }; set<int, cmp> s; ``` Loading