{"id":81789,"date":"2026-07-25T04:19:08","date_gmt":"2026-07-24T20:19:08","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/81789.html"},"modified":"2026-07-25T04:19:08","modified_gmt":"2026-07-24T20:19:08","slug":"%e3%80%90%e7%9f%a5%e8%af%86%e8%ae%b2%e8%a7%a3%e3%80%91-map%e5%92%8cset%e7%9a%84%e6%a8%a1%e6%8b%9f%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/81789.html","title":{"rendered":"\u3010\u77e5\u8bc6\u8bb2\u89e3\u3011 map\u548cset\u7684\u6a21\u62df\u5b9e\u73b0"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724201904-6a63c8b8af40c.jpg\" \/><\/p>\n<hr \/>\n<p>\u76ee\u5f55<\/p>\n<p style=\"margin-left:0px\">\u524d\u8a00<\/p>\n<p style=\"margin-left:0px\">Part1. map\u3001set\u4e0e\u7ea2\u9ed1\u6811<\/p>\n<p style=\"margin-left:0px\">Part2. \u7ea2\u9ed1\u6811\u7684\u6539\u9020<\/p>\n<p style=\"margin-left:40px\">Part2.1. map\u548cset\u5728\u4f20\u7ed9\u7ea2\u9ed1\u6811\u6a21\u677f\u53c2\u6570\u7684\u533a\u522b<\/p>\n<p style=\"margin-left:40px\">Part2.2. \u4f20\u7ed9\u7ea2\u9ed1\u6811\u6a21\u677f\u4e2d\u7b2c\u4e00\u4e2aK\u7684\u610f\u4e49<\/p>\n<p style=\"margin-left:40px\">Part2.3. \u8bbf\u95ee\u7ea2\u9ed1\u6811\u5185\u6570\u503c\u4e0e\u51fd\u6570\u4f20\u53c2\u4e4b\u95f4\u7684\u77db\u76fe<\/p>\n<p style=\"margin-left:0px\">Part3. \u8fed\u4ee3\u5668\u7684\u5b9e\u73b0<\/p>\n<p style=\"margin-left:40px\">Part3.1. &#043;&#043;\u7684\u91cd\u8f7d<\/p>\n<p style=\"margin-left:40px\">Part3.2. &#8211;\u7684\u91cd\u8f7d<\/p>\n<p style=\"margin-left:0px\">Part4. \u4ee3\u7801\u5b9e\u73b0<\/p>\n<p style=\"margin-left:40px\">\u00a0 Part4.1. set<\/p>\n<p style=\"margin-left:40px\">\u00a0 Part4.1. map<\/p>\n<p style=\"margin-left:40px\">Part4.2. \u7ea2\u9ed1\u6811<\/p>\n<p style=\"margin-left:0px\">Part5. \u7ed3\u8bed<\/p>\n<hr \/>\n<h2>\u524d\u8a00<\/h2>\n<p>\u00a0 \u4e86\u89e3STL\u5bb9\u5668\u6700\u597d\u7684\u65b9\u6cd5\u5c31\u662f\u4eb2\u81ea\u53bb\u5b9e\u73b0\u5b83&#xff0c;\u63a5\u4e0b\u6765\u8ddf\u968f\u5c0f\u7f16\u7684\u89c6\u89d2\u6765\u770b\u770b\u5728\u5b9e\u73b0map\u548cset\u5bb9\u5668\u4e2d\u4f1a\u9047\u5230\u7684\u95ee\u9898\u4e0e\u56f0\u96be\u5427\u3002<\/p>\n<hr \/>\n<p style=\"text-align:center\"><span style=\"color:#4da8ee\">let&#039;s go!!!!!!!!!<\/span><\/p>\n<hr \/>\n<h2>Part1. map\u3001set\u4e0e\u7ea2\u9ed1\u6811<\/h2>\n<p>\u00a0 map\u548cset\u7684\u5e95\u5c42\u90fd\u662f\u7ea2\u9ed1\u6811&#xff0c;\u90fd\u7528\u7ea2\u9ed1\u6811\u6765\u7ba1\u7406\u6570\u636e\u3002\u56e0\u6b64\u4e86\u89e3\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0\u662f\u5fc5\u8981\u7684&#xff0c;\u81f3\u4e8e\u600e\u4e48\u5b9e\u73b0\u7ea2\u9ed1\u6811&#xff0c;\u53ef\u4ee5\u770b\u8fd9\u4e24\u7bc7\u535a\u5ba2&#xff1a;<\/p>\n<hr \/>\n<p>\u3010\u77e5\u8bc6\u8bb2\u89e3\u3011 \u7ea2\u9ed1\u6811\u7684\u57fa\u672c\u63a5\u53e3\u8bb2\u89e3&#xff08;\u63d2\u5165\u3001\u5224\u65ad\u7b49\u7b49&#xff09;-CSDN\u535a\u5ba2<\/p>\n<p>\u3010\u77e5\u8bc6\u8bb2\u89e3\u3011 \u7ea2\u9ed1\u6811\u7684\u5220\u9664\u8bb2\u89e3-CSDN\u535a\u5ba2<\/p>\n<hr \/>\n<h2>Part2. \u7ea2\u9ed1\u6811\u7684\u6539\u9020<\/h2>\n<p>\u00a0 \u6211\u4eec\u77e5\u9053&#xff0c;set\u53ea\u5b58\u4e00\u4e2a\u6570\u636e\u5c31\u662f\u5355\u5355\u7684key&#xff0c;\u800cmap\u5b58\u4e24\u4e2a&#xff0c;\u5373key\u548cvalue&#xff0c;\u4e24\u4e2a\u6784\u6210\u6620\u5c04\u5173\u7cfb\u3002\u5173\u952e\u8fd9\u4e24\u4e2a\u5e95\u5c42\u90fd\u662f\u7ea2\u9ed1\u6811&#xff0c;\u8981\u60f3\u5b9e\u73b0\u4e0d\u662f\u5f97\u5b9e\u73b0\u4e24\u79cd\u7ea2\u9ed1\u6811&#xff1f;\u5b9e\u5219\u4e0d\u7528&#xff0c;\u8fd9\u91cc\u7528\u7684\u7684\u65b9\u6cd5\u5c31\u662fC&#043;&#043;\u4e2d\u7684<span style=\"color:#be191c\">\u6a21\u677f<\/span>&#xff0c;\u6211\u4eec\u6765\u770b\u3002<\/p>\n<p>\u00a0 \u540citerator\u548cconst_iterator\u7684\u5b9e\u73b0\u76f8\u4f3c&#xff0c;\u90fd\u662f<span style=\"color:#ed7976\">\u5229\u7528\u6a21\u677f\u4e0d\u5b9a\u53c2\u6570&#xff0c;\u4f9d\u9760\u7f16\u8bd1\u5668\u81ea\u5df1\u5b9e\u73b0\u6765\u7b80\u5316\u4ee3\u7801\u3002<\/span><\/p>\n<hr \/>\n<p> \u903b\u8f91&#xff1a;<br \/>\n&lt;1&gt; map\u3001set\u6a21\u677f&#xff1a;template&lt;class k,class v,\u00b7\u00b7\u00b7&gt;<br \/>\n&lt;2&gt; \u7ed9\u7ea2\u9ed1\u6811\u7684\u6a21\u677f&#xff1a;<br \/>\n    rb_tree&lt;k,k,\u00b7\u00b7\u00b7\u00b7&gt;\/\/set<br \/>\n    rb_tree&lt;k,pair&lt;k,v&gt;,\u00b7\u00b7\u00b7\u00b7&gt;\/\/map<br \/>\n&lt;3&gt; \u8282\u70b9&#xff1a;rb_tree_node&lt;class v&gt;<br \/>\n&lt;4&gt; rb_tree_node&lt;v&gt;\/\/set<br \/>\n    rb_tree_node&lt;pair&lt;k,v&gt;&gt;\/\/map <\/p>\n<hr \/>\n<h3>Part2.1. map\u548cset\u5728\u4f20\u7ed9\u7ea2\u9ed1\u6811\u6a21\u677f\u53c2\u6570\u7684\u533a\u522b<\/h3>\n<p>\u00a0 \u5728\u7ea2\u9ed1\u6811\u6a21\u677f\u4e2d&#xff0c;\u6211\u4eec\u7ed9\u51fa\u7684<span style=\"color:#ed7976\">\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u952e\u503c&#xff0c;\u7b2c\u4e8c\u4e2a\u7ed9\u51fa\u7684\u662f\u6570\u636e<\/span>&#xff0c;\u7531\u4e8e\u5728set\u4e2d\u6570\u636e\u548c\u952e\u503c\u90fd\u662f\u4e00\u8d77\u7684\u6240\u4ee5\u4e24\u4e2a\u5199\u76f8\u540c\u7684&#xff0c;\u4f46\u662f\u5728map\u4e2d\u5c31\u662f\u7ed9value\u4e86\u3002<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0 \u5728\u7ed9\u7ea2\u9ed1\u6811\u7684\u6a21\u677f\u4e2d&#xff0c;\u4e3a\u4ec0\u4e48map\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662fpair\u8fd9\u4e2a\u5462&#xff1f;\u56e0\u4e3a\u8fd9\u91cc\u6a21\u677f<span style=\"color:#faa572\">\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6307\u4ee3\u7684\u610f\u601d\u662f\u6307\u7ea2\u9ed1\u6811\u6bcf\u4e2a\u7ed3\u70b9\u7684\u7c7b\u578b<\/span>&#xff0c;\u5728map\u7684\u7ea2\u9ed1\u6811\u6bcf\u4e2a\u8282\u70b9\u7c7b\u578b\u81ea\u7136\u662fpair\u4e86&#xff0c;\u56e0\u4e3a\u6709\u4e24\u4e2a\u53c2\u6570\u3002<\/p>\n<hr \/>\n<h3>Part2.2. \u4f20\u7ed9\u7ea2\u9ed1\u6811\u6a21\u677f\u4e2d\u7b2c\u4e00\u4e2aK\u7684\u610f\u4e49<\/h3>\n<p>\u00a0\u00a0 \u90a3\u4e3a\u4ec0\u4e48\u8fd8\u8981\u591a\u4e00\u4e2a\u53c2\u6570&#xff0c;\u5c31\u662f\u7b2c\u4e00\u4e2ak&#xff1f;\u8fd9\u4e2a\u53c2\u6570\u4ee3\u8868\u7684\u662f\u952e\u503c&#xff0c;\u4e3a\u4ec0\u4e48\u8981\u628a\u8fd9\u4e2a\u72ec\u7acb\u51fa\u6765\u5462&#xff1f;<span style=\"color:#ed7976\">\u56e0\u4e3a\u5728\u7ea2\u9ed1\u6811\u7684\u63a5\u53e3\u4e2d&#xff0c;\u5220\u9664\u7b49<\/span><span style=\"color:#be191c\">\u9700\u8981\u8fd9\u4e2a\u7c7b\u578b<\/span><span style=\"color:#ed7976\">&#xff0c;\u6240\u4ee5\u5fc5\u987b\u628a\u8fd9\u4e2a\u72ec\u7acb\u51fa\u6765\u3002<\/span>\u800c\u6ca1\u6709\u5355\u72ec\u7684\u9700\u8981value\u7c7b\u578b\u7684\u63a5\u53e3&#xff0c;\u53ea\u4f1a\u9700\u8981\u952e\u503c\u548cvalue\u7ed3\u5408\u7684\u6574\u4f53\u7c7b\u578b\u3002\u6545\u4e0d\u7528\u628avalue\u72ec\u7acb\u51fa\u6765\u3002<\/p>\n<hr \/>\n<h3>Part2.3. \u8bbf\u95ee\u7ea2\u9ed1\u6811\u5185\u6570\u503c\u4e0e\u51fd\u6570\u4f20\u53c2\u4e4b\u95f4\u7684\u77db\u76fe<\/h3>\n<p>\u00a0 \u7531\u4e8emap\u4f20\u7ed9\u7ea2\u9ed1\u6811\u7c7b\u578b\u4e3apair&#xff0c;\u4ed6\u8bbf\u95ee\u7684\u65b9\u5f0f\u662f.first\/.second&#xff0c;\u4e0eset\u7684\u4e0d\u540c&#xff0c;\u5b83\u4f20\u7684\u5c31\u53ef\u4ee5\u76f4\u63a5\u7528\u3002\u4ed6\u4eec\u7684\u8bbf\u95ee\u65b9\u5f0f\u6709\u533a\u522b&#xff0c;\u6211\u4eec\u600e\u4e48\u89e3\u51b3\u5462&#xff1f;\u6211\u4eec<span style=\"color:#ed7976\">\u53ef\u4ee5\u5229\u7528\u4e00\u4e2a\u8403\u53d6\u5668<\/span>&#xff0c;\u5c31\u662f\u4eff\u51fd\u6570&#xff0c;\u6211\u4eec<span style=\"color:#ed7976\">\u7528\u8fd9\u4e2a\u51fd\u6570\u53d6\u51fa\u6765\u9700\u8981\u7684\u6570\u636e<\/span>&#xff0c;\u5728map\u548cset\u91cc\u9762\u5206\u522b\u6309\u7167\u9700\u6c42\u5b9e\u73b0&#xff0c;\u8fd9\u6837\u5c31\u89e3\u51b3\u4e86\u3002<\/p>\n<hr \/>\n<h2>Part3. \u8fed\u4ee3\u5668\u7684\u5b9e\u73b0<\/h2>\n<p>\u00a0 \u8fed\u4ee3\u5668\u7684\u5927\u4f53\u5b9e\u73b0\u4e3b\u8981\u8fd8\u662f\u548clist\u4e00\u6837&#xff0c;\u5173\u952e\u7684\u96be\u70b9\u5728\u4e8e&#043;&#043;\u7684\u91cd\u8f7d&#xff0c;\u6211\u4eec\u6765\u770b&#xff1a;<\/p>\n<hr \/>\n<h3>Part3.1. &#043;&#043;\u7684\u91cd\u8f7d<\/h3>\n<p>\u00a0 \u4e3a\u4ec0\u4e48&#043;&#043;\u5b9e\u73b0\u6bd4\u8f83\u96be&#xff0c;\u56e0\u4e3a\u6309\u7167\u6211\u4eec\u7684\u903b\u8f91&#xff0c;\u7ea2\u9ed1\u6811\u7684\u904d\u5386\u662f\u4e2d\u5e8f\u904d\u5386&#xff0c;\u4e5f\u5c31\u662f\u8bf4\u5728\u5f53\u524d<span style=\"color:#ed7976\">\u8fed\u4ee3\u5668&#043;&#043;\u540e\u5e94\u8be5\u5230\u5b83\u5728\u4e2d\u5e8f\u904d\u5386\u4e2d\u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\u5bf9\u5e94\u7684\u8fed\u4ee3\u5668<\/span>&#xff0c;\u5173\u952e\u6211\u4eec\u600e\u4e48\u641e\u5462&#xff1f;\u6211\u4eec\u6765\u770b\u56fe&#xff1a;<\/p>\n<hr \/>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724201907-6a63c8bb221eb.png\" \/><\/p>\n<hr \/>\n<p>\u00a0 \u6211\u4eec\u8981\u6c42A\u5904\u8fed\u4ee3\u5668&#043;&#043;\u540e\u7684\u7ed3\u679c&#xff0c;\u4e5f\u5c31\u662f\u8981\u5230\u4e0b\u4e00\u4e2a\u4e2d\u5e8f\u904d\u5386\u7684\u8fed\u4ee3\u5668\u3002\u4e2d\u5e8f\u904d\u5386\u7684\u987a\u5e8f\u662f<span style=\"color:#be191c\">\u5de6-&gt;\u6839-&gt;\u53f3<\/span>\u3002A\u4e3a\u8fd9\u4e2a\u5c40\u90e8\u6811\u7684\u6839&#xff0c;\u6211\u4eec\u73b0\u5728\u80fd\u5230\u8fd9\u4e2a\u4f4d\u7f6e<span style=\"color:#ed7976\">\u8bf4\u660e\u5de6\u8fb9&#xff08;b&#xff09;\u5df2\u7ecf\u904d\u5386\u5b8c\u4e86<\/span>&#xff0c;\u73b0\u5728\u8be5\u5230A\u7684\u53f3\u5b50\u6811\u4e86&#xff0c;\u5230A\u7684\u53f3\u5b50\u6811&#xff08;d&#xff09;&#xff0c;\u6309\u7167\u5de6-&gt;\u6839-&gt;\u53f3&#xff0c;\u5e94\u8be5\u904d\u5386\u4ed6\u7684\u5de6&#xff0c;\u5982\u6b64\u5faa\u73af&#xff0c;<span style=\"color:#ed7976\">\u76f4\u5230\u7ed3\u70b9\u7684\u5de6\u8fb9\u4e3anullptr\u4e3a\u6b62<\/span>&#xff0c;\u8fd9\u4e2a\u8282\u70b9\u5c31\u662f\u4e0b\u4e00\u4e2a\u4e2d\u5e8f\u904d\u5386\u7684\u8282\u70b9\u3002\u7ed3\u675f\u3002<\/p>\n<hr \/>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724201907-6a63c8bb61342.png\" \/><\/p>\n<hr \/>\n<p>\u00a0\u00a0\u6211\u4eec\u73b0\u5728\u80fd\u5230\u8fd9\u4e2a\u4f4d\u7f6e\u8bf4\u660e<span style=\"color:#ed7976\">\u5de6\u53f3\u5df2\u7ecf\u904d\u5386\u5b8c\u4e86<\/span>&#xff0c;\u8bf4\u660e\u5176\u4e2d\u5e8f\u904d\u5386\u7ed3\u675f\u4e86&#xff0c;\u8be5<span style=\"color:#ed7976\">\u56de\u5230\u4e0a\u4e00\u4e2a\u6839\u8282\u70b9\u4e86<\/span>&#xff0c;\u5230B\u3002<span style=\"color:#98c091\">\u7531\u4e8eA\u4e3aB\u53f3\u5b50&#xff0c;\u8bf4\u660eB\u53f3\u4e5f\u904d\u5386\u5b8c\u4e86&#xff0c;\u8bf4\u660eB\u7684\u4e2d\u5e8f\u904d\u5386\u4e5f\u7ed3\u675f\u4e86<\/span>&#xff0c;\u56de\u5230C&#xff0c;\u76f4\u5230D&#xff0c;\u7531\u4e8eC\u4e3aD\u7684\u5de6\u8fb9&#xff0c;<span style=\"color:#79c6cd\">\u8c61\u5f81\u8fd9\u5de6\u8fb9\u904d\u5386\u5b8c&#xff0c;\u8be5\u5230\u6839&#xff0c;\u4e5f\u5c31\u662fD\u672c\u8eab\u3002<\/span><span style=\"color:#ed7976\">\u8fd9\u4e2a\u8282\u70b9\u5c31\u662f\u4e0b\u4e00\u4e2a\u4e2d\u5e8f\u904d\u5386\u7684\u8282\u70b9<\/span>\u3002\u7ed3\u675f\u3002<\/p>\n<hr \/>\n<p>\u00a0 \u603b\u7ed3\u5c31\u662f<\/p>\n<p>&lt;1&gt;<span style=\"color:#ed7976\"> \u5f53\u5f53\u524d\u8282\u70b9\u7684\u53f3\u8fb9\u4e3a\u4e0d\u4e3a\u7a7a&#xff0c;\u627e\u5176\u53f3\u5b50\u6811\u7684\u6700\u5de6\u8282\u70b9\u3002<\/span><\/p>\n<p>&lt;2&gt; <span style=\"color:#e6b223\">\u82e5\u4e3a\u7a7a&#xff0c;\u5219\u5411\u4e0a\u7d22\u5f15&#xff0c;\u76f4\u5230\u627e\u5230\u8282\u70b9x\u7684\u7236\u4eb2\u8282\u70b9\u7684\u5de6\u8fb9\u4e3ax&#xff0c;\u8fd4\u56de\u7236\u4eb2\u8282\u70b9&#xff0c;\u5f53\u7136\u8981\u662f\u7236\u4eb2\u8282\u70b9\u4e3a\u7a7a&#xff0c;\u8bf4\u660e\u6b64\u65f6x\u4e3a\u6839\u8282\u70b9&#xff0c;\u8bf4\u660e\u6b64\u65f6\u6574\u4e2a\u6811\u904d\u5386\u5b8c\u4e86&#xff0c;\u8fd4\u56denullptr&#xff0c;\u7ed3\u675f\u3002<\/span><\/p>\n<hr \/>\n<h3>Part3.2. &#8211;\u7684\u91cd\u8f7d<\/h3>\n<p>\u00a0 \u6211\u4eec\u4e0a\u9762&#043;&#043;\u91cd\u8f7d\u7684\u5b9e\u73b0\u5176\u5b9e\u57cb\u4e0b\u4e86\u4e00\u4e2a\u9690\u7978&#xff0c;\u5c31\u662f\u5f53<span style=\"color:#be191c\">end()&#8211;<\/span>\u65f6\u5019&#xff0c;\u6211\u4eec\u6309\u7167\u4e0a\u9762\u7684\u903b\u8f91&#xff0c;<span style=\"color:#faa572\">end()\u4e3anullptr&#xff0c;\u5bf9\u8fd9\u4e2a&#8211;\u80af\u5b9a\u4f1a\u6709\u95ee\u9898<\/span>&#xff0c;\u56e0\u6b64\u6211\u4eec\u5c31\u8981\u5224\u65ad&#xff0c;<span style=\"color:#ed7976\">\u5f53\u5f53\u524d\u8282\u70b9\u4e3anullptr\u65f6&#xff0c;\u6211\u4eec\u8fd4\u56de_root\u7684\u6700\u53f3\u8282\u70b9&#xff08;\u4e2d\u5e8f\u904d\u5386\u7684\u6700\u540e\u4e00\u4e2a&#xff09;<\/span>&#xff0c;\u5173\u952e\u662f<span style=\"color:#faa572\">\u6211\u4eec\u7684\u8fed\u4ee3\u5668\u6ca1\u6709_root&#xff0c;\u56e0\u6b64\u6211\u4eec\u8981\u52a0\u4e00\u4e2a_root\u6210\u5458\u6765\u89e3\u51b3\u3002<\/span><\/p>\n<p>\u00a0<\/p>\n<p>p.s. STL\u5e93\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u662f\u7528\u4e00\u4e2a<span style=\"color:#be191c\">\u54e8\u5175\u4f4d<\/span>&#xff0c;\u5b83\u7684<span style=\"color:#98c091\">_left\u6307\u5411\u6574\u4e2a\u6811\u7684\u6700\u5de6<\/span>&#xff0c;<span style=\"color:#e6b223\">_right\u6307\u5411\u6700\u53f3&#xff0c;<\/span>\u5b83\u7684<span style=\"color:#98c091\">_parent\u6307\u5411_root<\/span>&#xff0c;<span style=\"color:#e6b223\">_root\u7684_parent\u6307\u5411\u5b83<\/span>&#xff0c;\u8fd9\u6837\u786e\u5b9e\u4f1a\u6bd4\u8f83\u65b9\u4fbf\u4f46\u662f\u6211\u4eec\u8fd8\u8981\u6ce8\u610f<span style=\"color:#9c8ec1\">erase&#xff0c;insert\u5bf9\u4e8e\u8fd9\u4e2a\u7684\u7ef4\u62a4\u3002<\/span><\/p>\n<hr \/>\n<h2>Part4. \u4ee3\u7801\u5b9e\u73b0<\/h2>\n<h3>\u00a0 Part4.1. set<\/h3>\n<p> #include&#034;\u5934.h&#034;<br \/>\nnamespace all<br \/>\n{<br \/>\ntemplate&lt;class k&gt;<br \/>\nclass set<br \/>\n{<br \/>\nstruct SetKeyOrT\/\/\u8403\u53d6\u5668<br \/>\n{<br \/>\nconst k&amp; operator()(const k&amp; key)<br \/>\n{<br \/>\nreturn key;<br \/>\n}<br \/>\n};<br \/>\npublic:<br \/>\ntypedef typename RBTree&lt;k,const k, SetKeyOrT&gt;::iterator iterator;<br \/>\ntypedef typename RBTree&lt;k, const k, SetKeyOrT&gt;::const_iterator const_iterator;<br \/>\niterator begin()<br \/>\n{<br \/>\nreturn _t.begin();<br \/>\n}<br \/>\niterator end()<br \/>\n{<br \/>\nreturn _t.end();<br \/>\n}<br \/>\nconst_iterator begin()const<br \/>\n{<br \/>\nreturn _t.begin();<br \/>\n}<br \/>\nconst_iterator end()const<br \/>\n{<br \/>\nreturn _t.end();<br \/>\n}<br \/>\nbool insert(const k&amp; key)<br \/>\n{<br \/>\nreturn _t.insert(key);<br \/>\n}<br \/>\nprivate:<br \/>\nRBTree&lt;k, const k, SetKeyOrT&gt; _t;<br \/>\n};<br \/>\n} <\/p>\n<hr \/>\n<h3>\u00a0 Part4.1. map<\/h3>\n<p> #include&#034;\u5934.h&#034;<br \/>\nnamespace all<br \/>\n{<br \/>\ntemplate&lt;class k,class v&gt;<br \/>\nclass map<br \/>\n{<br \/>\nstruct MapKeyOrT<br \/>\n{<br \/>\nconst k&amp; operator()(const pair&lt;k, v&gt;&amp; p)<br \/>\n{<br \/>\nreturn p.first;<br \/>\n}<br \/>\n};<br \/>\npublic:<br \/>\ntypedef typename RBTree&lt;const k, pair&lt;const k, v&gt;, MapKeyOrT&gt;::iterator iterator;<br \/>\ntypedef typename RBTree&lt;const k, pair&lt;const k, v&gt;, MapKeyOrT&gt;::const_iterator const_iterator;<br \/>\niterator begin()<br \/>\n{<br \/>\nreturn _t.begin();<br \/>\n}<br \/>\niterator end()<br \/>\n{<br \/>\nreturn _t.end();<br \/>\n}<br \/>\nconst_iterator begin()const<br \/>\n{<br \/>\nreturn _t.begin();<br \/>\n}<br \/>\nconst_iterator end()const<br \/>\n{<br \/>\nreturn _t.end();<br \/>\n}<br \/>\nbool insert(const pair&lt;k,v&gt;&amp; value)<br \/>\n{<br \/>\nreturn _t.insert(value);<br \/>\n}<br \/>\nprivate:<br \/>\nRBTree&lt;const k, pair&lt;const k, v&gt;, MapKeyOrT&gt; _t;<br \/>\n};<br \/>\n} <\/p>\n<hr \/>\n<h3>Part4.2. \u7ea2\u9ed1\u6811<\/h3>\n<p> #pragma once<br \/>\n#include&lt;iostream&gt;<br \/>\n#include&lt;vector&gt;<br \/>\n#include&lt;map&gt;<br \/>\nusing namespace std;<br \/>\nenum colour<br \/>\n{<br \/>\nRED<br \/>\n, BLACK<br \/>\n};<\/p>\n<p>template&lt;class T&gt;\/\/\u7ea2\u9ed1\u6811\u8282\u70b9<br \/>\nstruct RBTreeNode<br \/>\n{<br \/>\nT _data;<br \/>\nRBTreeNode&lt;T&gt;* _left;<br \/>\nRBTreeNode&lt;T&gt;* _right;<br \/>\nRBTreeNode&lt;T&gt;* _parent;<br \/>\ncolour _col;<\/p>\n<p>RBTreeNode(const T&amp; data)<br \/>\n:_data(data)<br \/>\n, _left(nullptr)<br \/>\n, _right(nullptr)<br \/>\n, _parent(nullptr)<br \/>\n{<br \/>\n}<br \/>\n};<\/p>\n<p>template&lt;class T,class Ref,class Ptr&gt;<br \/>\nclass RBTreeIterator;<\/p>\n<p>template&lt;class k , class T ,class KeyOrT&gt;<br \/>\nclass RBTree<br \/>\n{<br \/>\ntypedef RBTreeNode&lt;T&gt; Node;<br \/>\npublic:<br \/>\ntypedef RBTreeIterator&lt;T, T&amp;, T*&gt;  iterator;<br \/>\ntypedef RBTreeIterator&lt;T, const T&amp;, const T*&gt;  const_iterator;<\/p>\n<p>iterator begin()<br \/>\n{<br \/>\nNode* cur &#061; _root;<br \/>\nwhile (cur!&#061;nullptr&amp;&amp;cur-&gt;_left !&#061; nullptr)<br \/>\n{<br \/>\ncur &#061; cur-&gt;_left;<br \/>\n}<br \/>\nreturn iterator(cur,_root);<br \/>\n}<br \/>\niterator end()<br \/>\n{<br \/>\nreturn iterator(nullptr,_root);<br \/>\n}<br \/>\nconst_iterator begin()const<br \/>\n{<br \/>\nNode* cur &#061; _root;<br \/>\nwhile (cur !&#061; nullptr &amp;&amp; cur-&gt;_left !&#061; nullptr)<br \/>\n{<br \/>\ncur &#061; cur-&gt;_left;<br \/>\n}<br \/>\nreturn iterator(cur,_root);<br \/>\n}<br \/>\nconst_iterator end()const<br \/>\n{<br \/>\nreturn iterator(nullptr,_root);<br \/>\n}<br \/>\nbool insert(const T&amp; data)<br \/>\n{<br \/>\nif (_root &#061;&#061; nullptr)<br \/>\n{<br \/>\n_root &#061; new Node(data);<br \/>\n_root-&gt;_col &#061; BLACK;<br \/>\nreturn true;<br \/>\n}<br \/>\nNode* cur &#061; _root;<br \/>\nNode* parent &#061; nullptr;<br \/>\nwhile (cur !&#061; nullptr)<br \/>\n{<br \/>\nif (KeyOrT()(cur-&gt;_data) &gt; KeyOrT()(data))<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\ncur &#061; cur-&gt;_left;<br \/>\n}<br \/>\nelse if (KeyOrT()(cur-&gt;_data) &lt; KeyOrT()(data))<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\ncur &#061; cur-&gt;_right;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nreturn false;<br \/>\n}<br \/>\n}<br \/>\ncur &#061; new Node(data);<br \/>\ncur-&gt;_parent &#061; parent;<br \/>\nif (KeyOrT()(parent-&gt;_data) &gt; KeyOrT()(data))<br \/>\n{<br \/>\nparent-&gt;_left &#061; cur;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nparent-&gt;_right &#061; cur;<br \/>\n}<br \/>\ncur-&gt;_col &#061; RED;<br \/>\nwhile (parent !&#061; nullptr &amp;&amp; parent-&gt;_col &#061;&#061; RED)<br \/>\n{<br \/>\nNode* grandfather &#061; parent-&gt;_parent;<br \/>\nif (grandfather-&gt;_left &#061;&#061; parent)<br \/>\n{<br \/>\nNode* uncle &#061; grandfather-&gt;_right;<br \/>\nif (uncle !&#061; nullptr &amp;&amp; uncle-&gt;_col &#061;&#061; RED)<br \/>\n{<br \/>\nparent-&gt;_col &#061; BLACK;<br \/>\nuncle-&gt;_col &#061; BLACK;<br \/>\ngrandfather-&gt;_col &#061; RED;<br \/>\ncur &#061; grandfather;<br \/>\nparent &#061; cur-&gt;_parent;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (cur &#061;&#061; parent-&gt;_left)<br \/>\n{<br \/>\nRotateR(grandfather);<br \/>\ngrandfather-&gt;_col &#061; RED;<br \/>\ncur-&gt;_col &#061; RED;<br \/>\nparent-&gt;_col &#061; BLACK;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nRotateLR(grandfather);<br \/>\ngrandfather-&gt;_col &#061; RED;<br \/>\ncur-&gt;_col &#061; BLACK;<br \/>\nparent-&gt;_col &#061; RED;<br \/>\n}<br \/>\nbreak;<br \/>\n}<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nNode* uncle &#061; grandfather-&gt;_left;<br \/>\nif (uncle !&#061; nullptr &amp;&amp; uncle-&gt;_col &#061;&#061; RED)<br \/>\n{<br \/>\nparent-&gt;_col &#061; BLACK;<br \/>\nuncle-&gt;_col &#061; BLACK;<br \/>\ngrandfather-&gt;_col &#061; RED;<br \/>\ncur &#061; grandfather;<br \/>\nparent &#061; cur-&gt;_parent;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (cur &#061;&#061; parent-&gt;_right)<br \/>\n{<br \/>\nRotateL(grandfather);<br \/>\ngrandfather-&gt;_col &#061; RED;<br \/>\ncur-&gt;_col &#061; RED;<br \/>\nparent-&gt;_col &#061; BLACK;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nRotateRL(grandfather);<br \/>\ngrandfather-&gt;_col &#061; RED;<br \/>\ncur-&gt;_col &#061; BLACK;<br \/>\nparent-&gt;_col &#061; RED;<br \/>\n}<br \/>\nbreak;<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n_root-&gt;_col &#061; BLACK;<br \/>\nreturn true;<br \/>\n}<br \/>\nbool erase(const k&amp; key)<br \/>\n{<br \/>\nNode* z &#061; find(key);<br \/>\nNode* x &#061; nullptr;<br \/>\nif (z &#061;&#061; nullptr)<br \/>\n{<br \/>\nreturn false;<br \/>\n}<br \/>\ncolour col &#061; z-&gt;_col;<br \/>\nNode* parent &#061; z-&gt;_parent;<br \/>\nint lor &#061; 0;<br \/>\nif (z-&gt;_left &#061;&#061; nullptr&amp;&amp;z-&gt;_right!&#061;nullptr)<br \/>\n{<br \/>\nif (z-&gt;_parent &#061;&#061; nullptr)<br \/>\n{<br \/>\n_root &#061; z-&gt;_right;<br \/>\nz-&gt;_right-&gt;_parent &#061; nullptr;<br \/>\nz-&gt;_right-&gt;_col &#061; BLACK;<br \/>\ndelete z;<br \/>\nreturn true;<br \/>\n}<br \/>\nif (z-&gt;_parent-&gt;_left &#061;&#061; z)<br \/>\n{<br \/>\nz-&gt;_parent-&gt;_left &#061; z-&gt;_right;<br \/>\nlor &#061; -1;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nz-&gt;_parent-&gt;_right &#061; z-&gt;_right;<br \/>\nlor &#061; 1;<br \/>\n}<br \/>\nx &#061; z-&gt;_right;<br \/>\nz-&gt;_right-&gt;_parent &#061; z-&gt;_parent;<br \/>\ndelete z;<br \/>\n}<br \/>\nelse if (z-&gt;_left !&#061; nullptr &amp;&amp; z-&gt;_right &#061;&#061; nullptr)<br \/>\n{<br \/>\nif (z-&gt;_parent &#061;&#061; nullptr)<br \/>\n{<br \/>\n_root &#061; z-&gt;_left;<br \/>\nz-&gt;_left-&gt;_parent &#061; nullptr;<br \/>\nz-&gt;_left-&gt;_col &#061; BLACK;<br \/>\ndelete z;<br \/>\nreturn true;<br \/>\n}<br \/>\nif (z-&gt;_parent-&gt;_left &#061;&#061; z)<br \/>\n{<br \/>\nz-&gt;_parent-&gt;_left &#061; z-&gt;_left;<br \/>\nlor &#061; -1;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nz-&gt;_parent-&gt;_right &#061; z-&gt;_left;<br \/>\nlor &#061;1;<br \/>\n}<br \/>\nx &#061; z-&gt;_left;<br \/>\nz-&gt;_left-&gt;_parent &#061; z-&gt;_parent;<br \/>\ndelete z;<br \/>\n}<br \/>\nelse if (z-&gt;_left &#061;&#061; nullptr &amp;&amp; z-&gt;_right &#061;&#061; nullptr)<br \/>\n{<br \/>\nif (z-&gt;_parent &#061;&#061; nullptr)<br \/>\n{<br \/>\ndelete z;<br \/>\n_root &#061; nullptr;<br \/>\nreturn true;<br \/>\n}<br \/>\nif (z-&gt;_parent-&gt;_left &#061;&#061; z)<br \/>\n{<br \/>\nz-&gt;_parent-&gt;_left &#061; nullptr;<br \/>\nlor &#061; -1;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nz-&gt;_parent-&gt;_right &#061; nullptr;<br \/>\nlor &#061; 1;<br \/>\n}<br \/>\nx &#061; nullptr;<br \/>\ndelete z;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nNode* y &#061; z-&gt;_right;<br \/>\nwhile (y-&gt;_left !&#061; nullptr)<br \/>\n{<br \/>\ny &#061; y-&gt;_left;<br \/>\n}<br \/>\nz-&gt;_kv &#061; y-&gt;_kv;<br \/>\ncol &#061; y-&gt;_col;<br \/>\nparent &#061; y-&gt;_parent;<br \/>\nif (y-&gt;_parent-&gt;_left &#061;&#061; y)<br \/>\n{<br \/>\ny-&gt;_parent-&gt;_left &#061; y-&gt;_right;<br \/>\nlor &#061; -1;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\ny-&gt;_parent-&gt;_right &#061; y-&gt;_right;<br \/>\nlor &#061; 1;<br \/>\n}<br \/>\nx &#061; y-&gt;_right;<br \/>\nif (y-&gt;_right !&#061; nullptr)<br \/>\n{<br \/>\ny-&gt;_right-&gt;_parent &#061; y-&gt;_parent;<br \/>\n}<br \/>\ndelete y;<br \/>\n}<br \/>\nif (col &#061;&#061; RED)<br \/>\n{<br \/>\nreturn true;<br \/>\n}<br \/>\nNode* w &#061; nullptr;<br \/>\nif (lor &#061;&#061; 1)<br \/>\n{<br \/>\nw &#061; parent-&gt;_left;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nw &#061; parent-&gt;_right;<br \/>\n}<br \/>\nwhile (x !&#061; _root &amp;&amp; (x&#061;&#061;nullptr||x-&gt;_col&#061;&#061;BLACK))<br \/>\n{<br \/>\nif (lor &#061;&#061; -1)<br \/>\n{<br \/>\nif (w-&gt;_col &#061;&#061; RED)<br \/>\n{<br \/>\nw-&gt;_col &#061; BLACK;<br \/>\nparent-&gt;_col &#061; RED;<br \/>\nNode* tem &#061; w-&gt;_left;<br \/>\nRotateL(parent);<br \/>\nw &#061; tem;<br \/>\n}<br \/>\nelse if (w-&gt;_col &#061;&#061; BLACK&amp;&amp;(w-&gt;_left&#061;&#061;nullptr||w-&gt;_left-&gt;_col&#061;&#061;BLACK)&amp;&amp;(w-&gt;_right&#061;&#061;nullptr||w-&gt;_right-&gt;_col&#061;&#061;BLACK))<br \/>\n{<br \/>\nw-&gt;_col &#061; RED;<br \/>\nx &#061; parent;<br \/>\nif (x &#061;&#061; _root)<br \/>\n{<br \/>\nbreak;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (x-&gt;_parent-&gt;_left &#061;&#061; x)<br \/>\n{<br \/>\nw &#061; x-&gt;_parent-&gt;_right;<br \/>\nlor &#061; -1;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nw &#061; x-&gt;_parent-&gt;_left;<br \/>\nlor &#061; 1;<br \/>\n}<br \/>\nparent &#061; x-&gt;_parent;<br \/>\n}<br \/>\n}<br \/>\nelse if (w-&gt;_col &#061;&#061; BLACK &amp;&amp; w-&gt;_left !&#061; nullptr &amp;&amp; w-&gt;_left-&gt;_col &#061;&#061; RED &amp;&amp; (w-&gt;_right &#061;&#061; nullptr || w-&gt;_right-&gt;_col &#061;&#061; BLACK))<br \/>\n{<br \/>\nw-&gt;_left-&gt;_col &#061; BLACK;<br \/>\nw-&gt;_col &#061; RED;<br \/>\nNode* tem &#061; w-&gt;_left;<br \/>\nRotateR(w);<br \/>\nw &#061; tem;<br \/>\n}<br \/>\nelse if (w-&gt;_col &#061;&#061; BLACK &amp;&amp; w-&gt;_right !&#061; nullptr &amp;&amp; w-&gt;_right-&gt;_col &#061;&#061; RED)<br \/>\n{<br \/>\nw-&gt;_col &#061; parent-&gt;_col;<br \/>\nparent-&gt;_col &#061; BLACK;<br \/>\nw-&gt;_right-&gt;_col &#061; BLACK;<br \/>\nRotateL(parent);<br \/>\nx &#061; _root;<br \/>\n}<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (w-&gt;_col &#061;&#061; RED)<br \/>\n{<br \/>\nw-&gt;_col &#061; BLACK;<br \/>\nparent-&gt;_col &#061; RED;<br \/>\nNode* tem &#061; w-&gt;_right;<br \/>\nRotateR(parent);<br \/>\nw &#061; tem;<br \/>\n}<br \/>\nelse if (w-&gt;_col &#061;&#061; BLACK &amp;&amp; (w-&gt;_left &#061;&#061; nullptr || w-&gt;_left-&gt;_col &#061;&#061; BLACK) &amp;&amp; (w-&gt;_right &#061;&#061; nullptr || w-&gt;_right-&gt;_col &#061;&#061; BLACK))<br \/>\n{<br \/>\nw-&gt;_col &#061; RED;<br \/>\nx &#061; parent;<br \/>\nif (x &#061;&#061; _root)<br \/>\n{<br \/>\nbreak;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (x-&gt;_parent-&gt;_left &#061;&#061; x)<br \/>\n{<br \/>\nw &#061; x-&gt;_parent-&gt;_right;<br \/>\nlor &#061; -1;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nw &#061; x-&gt;_parent-&gt;_left;<br \/>\nlor &#061; 1;<br \/>\n}<br \/>\nparent &#061; x-&gt;_parent;<br \/>\n}<br \/>\n}<br \/>\nelse if (w-&gt;_col &#061;&#061; BLACK &amp;&amp; w-&gt;_right !&#061; nullptr &amp;&amp; w-&gt;_right-&gt;_col &#061;&#061; RED &amp;&amp; (w-&gt;_left &#061;&#061; nullptr || w-&gt;_left-&gt;_col &#061;&#061; BLACK))<br \/>\n{<br \/>\nw-&gt;_right-&gt;_col &#061; BLACK;<br \/>\nw-&gt;_col &#061; RED;<br \/>\nNode* tem &#061; w-&gt;_right;<br \/>\nRotateL(w);<br \/>\nw &#061; tem;<br \/>\n}<br \/>\nelse if (w-&gt;_col &#061;&#061; BLACK &amp;&amp; w-&gt;_left !&#061; nullptr &amp;&amp; w-&gt;_left-&gt;_col &#061;&#061; RED)<br \/>\n{<br \/>\nw-&gt;_col &#061; parent-&gt;_col;<br \/>\nparent-&gt;_col &#061; BLACK;<br \/>\nw-&gt;_left-&gt;_col &#061; BLACK;<br \/>\nRotateR(parent);<br \/>\nx &#061; _root;<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\nif (x !&#061; nullptr) {<br \/>\nx-&gt;_col &#061; BLACK;<br \/>\n}<br \/>\n_root-&gt;_col &#061; BLACK;<\/p>\n<p>return true;<br \/>\n}<br \/>\nvoid InOrder()const<br \/>\n{<br \/>\n_InOrder(_root);<br \/>\n}<br \/>\nvoid Is_RBTree()<br \/>\n{<br \/>\nif (_Is_RBTree(_root) !&#061; -1)<br \/>\n{<br \/>\ncout &lt;&lt; &#034;YES&#034; &lt;&lt; endl;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\ncout &lt;&lt; &#034;NO&#034; &lt;&lt; endl;<br \/>\n}<br \/>\n}<br \/>\nNode* find(const k&amp; key)<br \/>\n{<br \/>\nNode* cur &#061; _root;<br \/>\nwhile (cur !&#061; nullptr)<br \/>\n{<br \/>\nif (KeyOrT()(cur-&gt;_data) &gt; KeyOrT()(data))<br \/>\n{<br \/>\ncur &#061; cur-&gt;_left;<br \/>\n}<br \/>\nelse if (KeyOrT()(cur-&gt;_data) &lt; KeyOrT()(data))<br \/>\n{<br \/>\ncur &#061; cur-&gt;_right;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nreturn cur;<br \/>\n}<br \/>\n}<br \/>\nreturn nullptr;<br \/>\n}<br \/>\nprivate:<\/p>\n<p>void RotateR(Node* parent)<br \/>\n{<br \/>\nNode* subL &#061; parent-&gt;_left;<br \/>\nNode* subLR &#061; subL-&gt;_right;<br \/>\nparent-&gt;_left &#061; subLR;<br \/>\nsubL-&gt;_right &#061; parent;<br \/>\nif (parent-&gt;_parent !&#061; nullptr)<br \/>\n{<br \/>\nif (parent-&gt;_parent-&gt;_left &#061;&#061; parent)<br \/>\n{<br \/>\nparent-&gt;_parent-&gt;_left &#061; subL;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nparent-&gt;_parent-&gt;_right &#061; subL;<br \/>\n}<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n_root &#061; subL;<br \/>\n}<br \/>\nif (subLR !&#061; nullptr)<br \/>\n{<br \/>\nsubLR-&gt;_parent &#061; parent;<br \/>\n}<br \/>\nsubL-&gt;_parent &#061; parent-&gt;_parent;<br \/>\nparent-&gt;_parent &#061; subL;<br \/>\n}<br \/>\nvoid RotateL(Node* parent)<br \/>\n{<br \/>\nNode* subR &#061; parent-&gt;_right;<br \/>\nNode* subRL &#061; subR-&gt;_left;<br \/>\nparent-&gt;_right &#061; subRL;<br \/>\nsubR-&gt;_left &#061; parent;<br \/>\nif (parent-&gt;_parent !&#061; nullptr)<br \/>\n{<br \/>\nif (parent-&gt;_parent-&gt;_left &#061;&#061; parent)<br \/>\n{<br \/>\nparent-&gt;_parent-&gt;_left &#061; subR;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nparent-&gt;_parent-&gt;_right &#061; subR;<br \/>\n}<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n_root &#061; subR;<br \/>\n}<br \/>\nif (subRL !&#061; nullptr)<br \/>\n{<br \/>\nsubRL-&gt;_parent &#061; parent;<br \/>\n}<br \/>\nsubR-&gt;_parent &#061; parent-&gt;_parent;<br \/>\nparent-&gt;_parent &#061; subR;<br \/>\n}<br \/>\nvoid RotateLR(Node* parent)<br \/>\n{<br \/>\nNode* subL &#061; parent-&gt;_left;<br \/>\nRotateL(subL);<br \/>\nRotateR(parent);<br \/>\n}<br \/>\nvoid RotateRL(Node* parent)<br \/>\n{<br \/>\nNode* subR &#061; parent-&gt;_right;<br \/>\nRotateR(subR);<br \/>\nRotateL(parent);<br \/>\n}<br \/>\nvoid _InOrder(Node* root)const<br \/>\n{<br \/>\nif (root &#061;&#061; nullptr)<br \/>\nreturn;<br \/>\n_InOrder(root-&gt;_left);<br \/>\ncout &lt;&lt; root-&gt;_kv.second &lt;&lt; &#034;:&#034; &lt;&lt; root-&gt;_kv.second &lt;&lt; endl;<br \/>\n_InOrder(root-&gt;_right);<br \/>\n}<br \/>\nint _Is_RBTree(Node* root)<br \/>\n{<br \/>\nif (root &#061;&#061; nullptr)<br \/>\nreturn 0;<br \/>\nint left &#061; _Is_RBTree(root-&gt;_left);<br \/>\nint right &#061; _Is_RBTree(root-&gt;_right);<br \/>\nif (left &#061;&#061; -1 || right &#061;&#061; -1)<br \/>\n{<br \/>\nreturn -1;<br \/>\n}<br \/>\nif (left !&#061; right)<br \/>\n{<br \/>\nreturn -1;<br \/>\n}<br \/>\nif (root-&gt;_col &#061;&#061; RED)<br \/>\n{<br \/>\nif (root-&gt;_left !&#061; nullptr)<br \/>\n{<br \/>\nif (root-&gt;_left-&gt;_col !&#061; BLACK)<br \/>\n{<br \/>\nreturn -1;<br \/>\n}<br \/>\n}<br \/>\nif (root-&gt;_right !&#061; nullptr)<br \/>\n{<br \/>\nif (root-&gt;_right-&gt;_col !&#061; BLACK)<br \/>\n{<br \/>\nreturn -1;<br \/>\n}<br \/>\n}<br \/>\nreturn left &#043; 0;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nreturn left &#043; 1;<br \/>\n}<br \/>\n}<br \/>\nNode* _root &#061; nullptr;<br \/>\n};<\/p>\n<p>template&lt;class T, class Ref, class Ptr&gt;<br \/>\nclass RBTreeIterator<br \/>\n{<br \/>\ntypedef RBTreeIterator&lt;T, Ref, Ptr&gt; self;<br \/>\ntypedef RBTreeNode&lt;T&gt; Node;<br \/>\npublic:<br \/>\nRBTreeIterator(Node* node,Node* root)<br \/>\n:_node(node)<br \/>\n,_root(root)<br \/>\n{<br \/>\n}<br \/>\nself operator&#043;&#043;()<br \/>\n{<br \/>\nif (_node-&gt;_right !&#061; nullptr)<br \/>\n{<br \/>\nNode* cur &#061; _node-&gt;_right;<br \/>\nwhile(cur-&gt;_left !&#061; nullptr)<br \/>\n{<br \/>\ncur &#061; cur-&gt;_left;<br \/>\n}<br \/>\n_node &#061; cur;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nNode* parent &#061; _node-&gt;_parent;<br \/>\nwhile (parent!&#061;nullptr &amp;&amp; _node !&#061; parent-&gt;_left)<br \/>\n{<br \/>\n_node &#061; parent;<br \/>\nparent &#061; parent-&gt;_parent;<br \/>\n}<br \/>\n_node &#061; parent;<br \/>\n}<br \/>\nreturn *this;<br \/>\n}<br \/>\nself operator&#8211;()<br \/>\n{<br \/>\nif (_node &#061;&#061; nullptr)<br \/>\n{<br \/>\nNode* cur &#061; _root;<br \/>\nwhile (cur-&gt;_right !&#061; nullptr)<br \/>\n{<br \/>\ncur &#061; cur-&gt;_right;<br \/>\n}<br \/>\n_node &#061; cur;<br \/>\nreturn *this;<br \/>\n}<br \/>\nelse<br \/>\n{<\/p>\n<p>if (_node-&gt;_left !&#061; nullptr)<br \/>\n{<br \/>\nNode* cur &#061; _node-&gt;_left;<br \/>\nwhile (cur-&gt;_right !&#061; nullptr)<br \/>\n{<br \/>\ncur &#061; cur-&gt;_right;<br \/>\n}<br \/>\n_node &#061; cur;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nNode* parent &#061; _node-&gt;_parent;<br \/>\nwhile (parent !&#061; nullptr &amp;&amp; _node !&#061; parent-&gt;_right)<br \/>\n{<br \/>\n_node &#061; parent;<br \/>\nparent &#061; parent-&gt;_parent;<br \/>\n}<br \/>\n_node &#061; parent;<br \/>\n}<br \/>\n}<br \/>\nreturn *this;<br \/>\n}<br \/>\nRef operator*()<br \/>\n{<br \/>\nreturn _node-&gt;_data;<br \/>\n}<br \/>\nPtr operator-&gt;()<br \/>\n{<br \/>\nreturn &amp;(_node-&gt;_data);<br \/>\n}<br \/>\nbool operator!&#061;(const self&amp; s)const<br \/>\n{<br \/>\nreturn s._node !&#061; _node;<br \/>\n}<br \/>\nprivate:<br \/>\nNode* _node;<br \/>\nNode* _root;\/\/\u591a\u4e00\u4e2a_root<br \/>\n}; <\/p>\n<hr \/>\n<h2>Part5. \u7ed3\u8bed<\/h2>\n<p>\u00a0\u8fd9\u7bc7\u6587\u7ae0\u6211\u4eec\u8ba4\u8bc6\u5230\u4e86map\u548cset\u7684\u5b9e\u73b0&#xff0c;\u63a5\u4e0b\u6765&#xff0c;\u5c0f\u7f16\u4f1a\u5e26\u6765\u54c8\u5e0c\u8868\u7684\u76f8\u5173\u77e5\u8bc6&#xff0c;\u656c\u8bf7\u671f\u5f85~<\/p>\n<p>\u00a0\u6700\u540e&#xff0c;\u795d\u5927\u5bb6\u53ef\u4ee5&#xff1a;<span style=\"color:#fe2c24\">\u6625\u98ce\u5f97\u610f\u9a6c\u8e44\u75be&#xff0c;\u4e00\u65e5\u770b\u5c3d\u957f\u5b89\u82b1&#xff01;<\/span><\/p>\n<p>\u00a0\u6700\u540e\u7684\u6700\u540e&#xff0c;\u8981\u662f\u89c9\u5f97\u672c\u6587\u8fd8\u53ef\u4ee5\u7684\u8bdd&#xff0c;\u53ef\u4ee5\u70b9\u70b9\u8d5e&#xff0c;\u5173\u6ce8\u5c0f\u7f16\u4e00\u6ce2&#xff0c;<span style=\"color:#fe2c24\">\u8c22\u8c22\u5927\u5bb6&#xff01;~<\/span><\/p>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55<br \/>\n\u524d\u8a00<br \/>\nPart1. map\u3001set\u4e0e\u7ea2\u9ed1\u6811<br \/>\nPart2. \u7ea2\u9ed1\u6811\u7684\u6539\u9020<br \/>\nPart2.1. map\u548cset\u5728\u4f20\u7ed9\u7ea2\u9ed1\u6811\u6a21\u677f\u53c2\u6570\u7684\u533a\u522b<br \/>\nPart2.2. \u4f20\u7ed9\u7ea2\u9ed1\u6811\u6a21\u677f\u4e2d\u7b2c\u4e00\u4e2aK\u7684\u610f\u4e49<br \/>\nPart2.3. \u8bbf\u95ee\u7ea2\u9ed1\u6811\u5185\u6570\u503c\u4e0e\u51fd\u6570\u4f20\u53c2\u4e4b\u95f4\u7684\u77db\u76fe<br \/>\nPart3. \u8fed\u4ee3\u5668\u7684\u5b9e\u73b0<br \/>\nPart3.1. \u7684\u91cd\u8f7d<br \/>\nPart3.2. &#8211;\u7684\u91cd\u8f7d<br \/>\nPart4. \u4ee3\u7801\u5b9e\u73b0 Part4.1. set Part4.1. map<br \/>\nPart4.2. \u7ea2\u9ed1\u6811<br \/>\nPart5. \u7ed3\u8bed \u524d\u8a00 <\/p>\n","protected":false},"author":2,"featured_media":81786,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9137,9138,9139,55,4233,1813],"topic":[],"class_list":["post-81789","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-atomgit","tag-set","tag-9139","tag-c","tag-map","tag-1813"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u77e5\u8bc6\u8bb2\u89e3\u3011 map\u548cset\u7684\u6a21\u62df\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/81789.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u77e5\u8bc6\u8bb2\u89e3\u3011 map\u548cset\u7684\u6a21\u62df\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 \u524d\u8a00 Part1. map\u3001set\u4e0e\u7ea2\u9ed1\u6811 Part2. \u7ea2\u9ed1\u6811\u7684\u6539\u9020 Part2.1. map\u548cset\u5728\u4f20\u7ed9\u7ea2\u9ed1\u6811\u6a21\u677f\u53c2\u6570\u7684\u533a\u522b Part2.2. \u4f20\u7ed9\u7ea2\u9ed1\u6811\u6a21\u677f\u4e2d\u7b2c\u4e00\u4e2aK\u7684\u610f\u4e49 Part2.3. \u8bbf\u95ee\u7ea2\u9ed1\u6811\u5185\u6570\u503c\u4e0e\u51fd\u6570\u4f20\u53c2\u4e4b\u95f4\u7684\u77db\u76fe Part3. \u8fed\u4ee3\u5668\u7684\u5b9e\u73b0 Part3.1. \u7684\u91cd\u8f7d Part3.2. --\u7684\u91cd\u8f7d Part4. \u4ee3\u7801\u5b9e\u73b0 Part4.1. set Part4.1. map Part4.2. \u7ea2\u9ed1\u6811 Part5. \u7ed3\u8bed \u524d\u8a00\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/81789.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-24T20:19:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724201904-6a63c8b8af40c.jpg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/81789.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/81789.html\",\"name\":\"\u3010\u77e5\u8bc6\u8bb2\u89e3\u3011 map\u548cset\u7684\u6a21\u62df\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-24T20:19:08+00:00\",\"dateModified\":\"2026-07-24T20:19:08+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/81789.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/81789.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/81789.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u77e5\u8bc6\u8bb2\u89e3\u3011 map\u548cset\u7684\u6a21\u62df\u5b9e\u73b0\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010\u77e5\u8bc6\u8bb2\u89e3\u3011 map\u548cset\u7684\u6a21\u62df\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/81789.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u77e5\u8bc6\u8bb2\u89e3\u3011 map\u548cset\u7684\u6a21\u62df\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 \u524d\u8a00 Part1. map\u3001set\u4e0e\u7ea2\u9ed1\u6811 Part2. \u7ea2\u9ed1\u6811\u7684\u6539\u9020 Part2.1. map\u548cset\u5728\u4f20\u7ed9\u7ea2\u9ed1\u6811\u6a21\u677f\u53c2\u6570\u7684\u533a\u522b Part2.2. \u4f20\u7ed9\u7ea2\u9ed1\u6811\u6a21\u677f\u4e2d\u7b2c\u4e00\u4e2aK\u7684\u610f\u4e49 Part2.3. \u8bbf\u95ee\u7ea2\u9ed1\u6811\u5185\u6570\u503c\u4e0e\u51fd\u6570\u4f20\u53c2\u4e4b\u95f4\u7684\u77db\u76fe Part3. \u8fed\u4ee3\u5668\u7684\u5b9e\u73b0 Part3.1. \u7684\u91cd\u8f7d Part3.2. --\u7684\u91cd\u8f7d Part4. \u4ee3\u7801\u5b9e\u73b0 Part4.1. set Part4.1. map Part4.2. \u7ea2\u9ed1\u6811 Part5. \u7ed3\u8bed \u524d\u8a00","og_url":"https:\/\/www.wsisp.com\/helps\/81789.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-24T20:19:08+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260724201904-6a63c8b8af40c.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"11 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/81789.html","url":"https:\/\/www.wsisp.com\/helps\/81789.html","name":"\u3010\u77e5\u8bc6\u8bb2\u89e3\u3011 map\u548cset\u7684\u6a21\u62df\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-24T20:19:08+00:00","dateModified":"2026-07-24T20:19:08+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/81789.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/81789.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/81789.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u77e5\u8bc6\u8bb2\u89e3\u3011 map\u548cset\u7684\u6a21\u62df\u5b9e\u73b0"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/81789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=81789"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/81789\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/81786"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=81789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=81789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=81789"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=81789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}