{"id":594,"date":"2020-05-25T17:50:33","date_gmt":"2020-05-25T09:50:33","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=594"},"modified":"2021-05-01T20:59:21","modified_gmt":"2021-05-01T12:59:21","slug":"%e5%b8%b8%e7%94%a8stl%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2020\/05\/25\/%e5%b8%b8%e7%94%a8stl%e7%9a%84%e4%bd%bf%e7%94%a8\/","title":{"rendered":"\u5e38\u7528STL\u7684\u4f7f\u7528"},"content":{"rendered":"<h2>STL<\/h2>\n<p>standard template library, \u6807\u51c6\u6a21\u677f\u5e93\u3002\u5e38\u89c1\u7684\u5bb9\u5668\u6709: vector, map, queue, stack, pair, set\u7b49<br \/>\n\u7c7b\u4f3c\u4e8e\u6307\u9488\uff0cSTL\u53ef\u4ee5\u901a\u8fc7\u8fed\u4ee3\u5668\u8bbf\u95ee\u67d0\u4e2a\u5bb9\u5668\u7684\u67d0\u4e2a\u5143\u7d20\u3002<\/p>\n<h3>\u4f18\u5148\u6743\u961f\u5217<\/h3>\n<p>priority_queue\\&lt;T><\/p>\n<h5>\u4f18\u5148\u6743\u961f\u5217\u5bf9\u57fa\u672c\u7c7b\u578b\u9ed8\u8ba4\u662f<strong>\u503c\u5927\u7684\u4f18\u5148\u6743\u5927<\/strong>\u3002<\/h5>\n<p>int, char, string\u7b49\uff0c\u90fd\u53ef\u4ee5\u6bd4\u8f83\u5927\u5c0f\u3002<\/p>\n<pre><code class=\"language-c++\">\/\/\u503c\u5c0f\u7684\u4f18\u5148\u6743\u5c0f\npriority_queue&lt;int, vector&lt;int&gt;, greater&lt;int&gt;&gt; q;\n\n\/\/\u503c\u5927\u7684\u4f18\u5148\u6743\u5927\npriority_queue&lt;int, vector&lt;int&gt;, less&lt;int&gt;&gt; q;<\/code><\/pre>\n<h5>\u5bf9\u975e\u57fa\u672c\u7c7b\u578b\u9700\u8981\u91cd\u8f7d\u8fd0\u7b97\u7b26<\/h5>\n<p>\u5bf9\u4e8e\u975e\u57fa\u672c\u7c7b\u578b\u4f7f\u7528\u4f18\u5148\u6743\u961f\u5217\u65f6(struct\uff0cclass)\uff0c\u8981<strong>\u91cd\u8f7d\u5c0f\u4e8e\u8fd0\u7b97\u7b26<\/strong>\u3002<\/p>\n<h3>map<\/h3>\n<p>map&lt;\u952e\u503c\uff0c\u6620\u5c04\u503c&gt;<br \/>\nmap\u662fSTL\u7684\u91cd\u8981\u5bb9\u5668\u4e4b\u4e00\uff0c\u662f\u4e00\u4e2a\u53ef\u4ee5\u8fbe\u5230\u4e00\u4e00\u6620\u5c04\u6548\u679c\u7684\u6570\u636e\u7ed3\u6784\u3002<br \/>\n\u7528\u8d77\u6765\u5f88\u6162\u7684\uff0c\uff0c\uff0c\u4e5f\u5360\u5de8\u5927\u7684\u7a7a\u95f4<\/p>\n<p>map\u91cc\u7684\u952e\u503c\uff0c\u6620\u5c04\u503c\u90fd\u662f\u9ed8\u8ba4\u4ece\u5c0f\u5230\u5927\u6392\u597d\u8bc4\u7684\u3002<\/p>\n<pre><code class=\"language-c++\">\/\/\u4e00\u822c\u4f7f\u7528\u65b9\u6cd5\nmap&lt;int, int&gt; mp;\nmp[10] = 5;                 \/\/\u6267\u884c\u6b64\u53e5\u4e4b\u524d\uff0cmp[10]\u4e0d\u5b58\u5728(\u6ce8\u610f\u662f\u4e0d\u5b58\u5728\uff0c\u4e0d\u662f\u4e3a0)\uff0c\u6267\u884c\u540e\u81ea\u52a8\u4e3a10\u63d0\u4f9b\u6620\u5c04\u503c\ncout &lt;&lt; mp[10] &lt;&lt; endl;     \/\/ 5\n\n\/\/\u5bf9map\u91cc\u7684\u6bcf\u4e00\u5bf9&lt;\u952e\u503c\uff0c\u6620\u5c04\u503c&gt;\u8fdb\u884c\u8bbf\u95ee\nmap&lt;int, int&gt;::iterator i = mp.begin();\ni++;            \/\/\u8be5\u8bed\u53e5\u53ef\u5c06\u8fed\u4ee3\u5668i\u79fb\u52a8\u5230\u4e0b\u4e00\u4f4d\ni-&gt;first;       \/\/\u8bbf\u95ee\u952e\u503c\ni-&gt;second;      \/\/\u8bbf\u95ee\u6620\u5c04\u503c\n\n\/\/count()\u51fd\u6570\nmp.count(50);               \/\/\u68c0\u67e5mp\u662f\u5426\u670950\u8fd9\u4e2a\u952e\u503c\uff0c\u8303\u56f4\u7c7b\u578b\u4e3a bool\n\n\/\/\n<\/code><\/pre>\n<h5>unordered_map<\/h5>\n<p>\u5f53\u4e0d\u9700\u8981\u5176\u952e\u503c\u6216\u8005\u6620\u5c04\u503c\u6309\u7279\u5b9a\u65b9\u5f0f\u6392\u5e8f\u65f6\uff0c\u6700\u597d\u4f7f\u7528unordered_map\uff0c\u4ec5\u901a\u8fc7\u952e\u503c\u5feb\u901f\u8bbf\u95ee\u6620\u5c04\u503c(\u5e38\u91cf\u65f6\u95f4\u590d\u6742\u5ea6)\u3002<br \/>\n\u5176\u4f59\u7684\u4f7f\u7528\u65b9\u6cd5\u540cmap<\/p>\n","protected":false},"excerpt":{"rendered":"<p>STL standard template library, \u6807\u51c6\u6a21\u677f\u5e93\u3002\u5e38\u89c1\u7684\u5bb9\u5668\u6709: vecto [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/594"}],"collection":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/comments?post=594"}],"version-history":[{"count":7,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/594\/revisions"}],"predecessor-version":[{"id":1142,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/594\/revisions\/1142"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=594"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}