{"id":44890,"date":"2025-06-21T06:06:07","date_gmt":"2025-06-20T22:06:07","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/44890.html"},"modified":"2025-06-21T06:06:07","modified_gmt":"2025-06-20T22:06:07","slug":"%e3%80%90c%e3%80%91-%e4%bb%8e%e9%9b%b6%e5%bc%80%e5%a7%8b%e5%b0%81%e8%a3%85-map-%e4%b8%8e-set%ef%bc%9a%e5%ae%9e%e7%8e%b0%e4%b8%8e%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/44890.html","title":{"rendered":"\u3010C++\u3011\u2014\u2014 \u4ece\u96f6\u5f00\u59cb\u5c01\u88c5 Map \u4e0e Set\uff1a\u5b9e\u73b0\u4e0e\u4f18\u5316"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"726\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250620220604-6855db4c39a4f.gif\" width=\"1200\" \/><\/p>\n<p style=\"text-align:center\"><span style=\"color:#38d8f0\">\u4eba\u751f\u7684\u6001\u5ea6\u662f&#xff0c;\u62b1\u6700\u5927\u7684\u5e0c\u671b&#xff0c;\u5c3d\u6700\u5927\u7684\u52aa\u529b&#xff0c;\u505a\u6700\u574f\u7684\u6253\u7b97\u3002<\/span><\/p>\n<p style=\"text-align:center\">\u2014\u2014 \u67cf\u62c9\u56fe \u300a\u7406\u60f3\u56fd\u300b<\/p>\n<hr \/>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"1%E3%80%81%E7%90%86%E8%AE%BA%E5%9F%BA%E7%9F%B3%E2%80%94%E2%80%94%E6%B7%B1%E5%BA%A6%E5%89%96%E6%9E%90%20BSTree%E3%80%81AVLTree%20%E4%B8%8E%20RBTree%20%E7%9A%84%E6%A6%82%E5%BF%B5%E5%8C%BA%E5%88%AB-toc\" style=\"margin-left:0px\">1\u3001\u7406\u8bba\u57fa\u77f3\u2014\u2014\u6df1\u5ea6\u5256\u6790 BSTree\u3001AVLTree \u4e0e RBTree \u7684\u6982\u5ff5\u533a\u522b<\/p>\n<p id=\"2%E3%80%81%E8%BF%AD%E4%BB%A3%E5%99%A8%E6%9C%BA%E5%88%B6%E2%80%94%E2%80%94RBTree%20%E8%BF%AD%E4%BB%A3%E5%99%A8%E7%9A%84%E6%9E%B6%E6%9E%84%E4%B8%8E%E5%B7%A5%E7%A8%8B%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:0px\">2\u3001\u8fed\u4ee3\u5668\u673a\u5236\u2014\u2014RBTree \u8fed\u4ee3\u5668\u7684\u67b6\u6784\u4e0e\u5de5\u7a0b\u5b9e\u73b0<\/p>\n<p id=\"3%E3%80%81%E9%AB%98%E7%BA%A7%E5%AE%B9%E5%99%A8%E8%AE%BE%E8%AE%A1%E2%80%94%E2%80%94Map%20%E4%B8%8E%20Set%20%E7%9A%84%E6%A8%A1%E5%9D%97%E5%8C%96%E5%B0%81%E8%A3%85-toc\" style=\"margin-left:0px\">3\u3001\u9ad8\u7ea7\u5bb9\u5668\u8bbe\u8ba1\u2014\u2014Map \u4e0e Set \u7684\u6a21\u5757\u5316\u5c01\u88c5<\/p>\n<p id=\"3.1%20%E6%B3%9B%E5%9E%8B%E6%94%AF%E6%8C%81%E5%A2%9E%E5%BC%BA%E2%80%94%E2%80%94RBTree%20%E6%A8%A1%E6%9D%BF%E5%8F%82%E6%95%B0%E8%AE%BE%E8%AE%A1%E4%BC%98%E5%8C%96-toc\" style=\"margin-left:40px\">3.1 \u6cdb\u578b\u652f\u6301\u589e\u5f3a\u2014\u2014RBTree \u6a21\u677f\u53c2\u6570\u8bbe\u8ba1\u4f18\u5316<\/p>\n<p id=\"3.2%C2%A0Set%20%E5%AE%B9%E5%99%A8%E6%9E%84%E5%BB%BA%E2%80%94%E2%80%94%E9%9D%A2%E5%90%91%E9%9B%86%E5%90%88%E6%93%8D%E4%BD%9C%E7%9A%84%E4%BC%98%E5%8C%96%E8%AE%BE%E8%AE%A1-toc\" style=\"margin-left:40px\">3.2\u00a0Set \u5bb9\u5668\u6784\u5efa\u2014\u2014\u9762\u5411\u96c6\u5408\u64cd\u4f5c\u7684\u4f18\u5316\u8bbe\u8ba1<\/p>\n<p id=\"%C2%A03.3%C2%A0Map%20%E5%AE%B9%E5%99%A8%E6%9E%84%E5%BB%BA%E2%80%94%E2%80%94%E9%AB%98%E6%95%88%E9%94%AE%E5%80%BC%E5%AD%98%E5%82%A8%E7%9A%84%E5%B0%81%E8%A3%85%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:40px\">\u00a03.3\u00a0Map \u5bb9\u5668\u6784\u5efa\u2014\u2014\u9ad8\u6548\u952e\u503c\u5b58\u50a8\u7684\u5c01\u88c5\u5b9e\u73b0<\/p>\n<p id=\"Thanks%E8%B0%A2%E8%B0%A2%E9%98%85%E8%AF%BB%EF%BC%81%EF%BC%81%EF%BC%81-toc\" style=\"margin-left:0px\">Thanks\u8c22\u8c22\u9605\u8bfb&#xff01;&#xff01;&#xff01;<\/p>\n<hr \/>\n<h2 id=\"1%E3%80%81%E7%90%86%E8%AE%BA%E5%9F%BA%E7%9F%B3%E2%80%94%E2%80%94%E6%B7%B1%E5%BA%A6%E5%89%96%E6%9E%90%20BSTree%E3%80%81AVLTree%20%E4%B8%8E%20RBTree%20%E7%9A%84%E6%A6%82%E5%BF%B5%E5%8C%BA%E5%88%AB\">1\u3001\u7406\u8bba\u57fa\u77f3\u2014\u2014\u6df1\u5ea6\u5256\u6790 BSTree\u3001AVLTree \u4e0e RBTree \u7684\u6982\u5ff5\u533a\u522b<\/h2>\n<p>\u4e3a\u4e86\u5b9e\u73b0 Map \u548c Set \u7684\u5c01\u88c5&#xff0c;\u6211\u4eec\u9996\u5148\u8fdb\u884c\u4e86\u5145\u5206\u7684\u77e5\u8bc6\u50a8\u5907&#xff0c;\u786e\u4fdd\u7406\u89e3\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u7684\u539f\u7406\u4e0e\u5b9e\u73b0\u3002<\/p>\n<p><span style=\"color:#0d0016\">\u4e8c\u53c9\u641c\u7d22\u6811\u53ca\u5176\u53d8\u79cd<\/span><\/p>\n<p>\u4e3a\u4e86\u6df1\u5165\u7406\u89e3 Map \u548c Set \u7684\u5e95\u5c42\u539f\u7406&#xff0c;\u6211\u4eec\u4ece\u4e8c\u53c9\u641c\u7d22\u6811 (BST)\u5165\u624b\u3002\u4e8c\u53c9\u641c\u7d22\u6811\u5728\u4e8c\u53c9\u6811\u7684\u57fa\u7840\u4e0a\u52a0\u5165\u4e86\u4ee5\u4e0b\u91cd\u8981\u7279\u6027&#xff1a;<\/p>\n<ul>\n<li>\u82e5\u5de6\u5b50\u6811\u4e0d\u4e3a\u7a7a&#xff0c;\u5219\u5de6\u5b50\u6811\u4e0a\u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u5c0f\u4e8e\u6839\u8282\u70b9\u7684\u503c&#xff1b;<\/li>\n<li>\u82e5\u53f3\u5b50\u6811\u4e0d\u4e3a\u7a7a&#xff0c;\u5219\u53f3\u5b50\u6811\u4e0a\u6240\u6709\u8282\u70b9\u7684\u503c\u90fd\u5927\u4e8e\u6839\u8282\u70b9\u7684\u503c&#xff1b;<\/li>\n<li>\u5de6\u53f3\u5b50\u6811\u4e5f\u5fc5\u987b\u5206\u522b\u6ee1\u8db3\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6027\u8d28\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u7ed3\u6784\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u53ef\u4ee5\u6709\u6548\u652f\u6301\u5feb\u901f\u67e5\u627e&#xff0c;\u4f46\u5728\u67d0\u4e9b\u6781\u7aef\u60c5\u51b5\u4e0b&#xff08;\u4f8b\u5982\u5355\u4fa7\u6811\u5f62\u7ed3\u6784&#xff09;&#xff0c;\u641c\u7d22\u6548\u7387\u4f1a\u9000\u5316\u4e3a O(n)\u3002\u56e0\u6b64&#xff0c;\u6211\u4eec\u5f15\u5165\u4e86\u66f4\u4e3a\u9ad8\u6548\u7684\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811&#xff0c;\u5176\u4e2d AVL\u6811 \u548c \u7ea2\u9ed1\u6811 (RBTree) \u662f\u4e24\u79cd\u7ecf\u5178\u7684\u53d8\u79cd&#xff0c;\u5b83\u4eec\u901a\u8fc7\u4e0d\u540c\u7684\u65b9\u5f0f\u63d0\u9ad8\u4e86\u6027\u80fd\u4e0e\u7a33\u5b9a\u6027\u3002<\/p>\n<p><span style=\"color:#0d0016\">\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811&#xff1a;AVL \u6811\u4e0e\u7ea2\u9ed1\u6811<\/span><\/p>\n<p>AVL \u6811 \u548c \u7ea2\u9ed1\u6811 \u90fd\u662f\u5728\u4fdd\u6301\u4e8c\u53c9\u641c\u7d22\u6811\u57fa\u672c\u6027\u8d28\u7684\u57fa\u7840\u4e0a&#xff0c;\u901a\u8fc7\u65cb\u8f6c\u4e0e\u91cd\u65b0\u5e73\u8861\u64cd\u4f5c&#xff0c;\u786e\u4fdd\u6811\u7684\u9ad8\u5ea6\u7ef4\u6301\u5728\u4e00\u4e2a\u76f8\u5bf9\u5e73\u8861\u7684\u72b6\u6001&#xff0c;\u4ece\u800c\u4fdd\u8bc1\u4e86\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u59cb\u7ec8\u4e3a O(log n)\u3002\u5b83\u4eec\u7684\u51fa\u73b0\u5927\u5927\u63d0\u5347\u4e86\u4e8c\u53c9\u641c\u7d22\u6811\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u6027\u80fd\u4e0e\u53ef\u9760\u6027\u3002<\/p>\n<ul>\n<li>\n<p>AVL \u6811 \u589e\u52a0\u4e86\u4ee5\u4e0b\u7279\u6027&#xff1a;<\/p>\n<ul>\n<li>\u5b83\u7684\u5de6\u53f3\u5b50\u6811\u5fc5\u987b\u90fd\u662f AVL \u6811&#xff1b;<\/li>\n<li>\u5de6\u53f3\u5b50\u6811\u9ad8\u5ea6\u5dee&#xff08;\u5e73\u8861\u56e0\u5b50&#xff09;\u4e0d\u80fd\u8d85\u8fc7 1&#xff08;\u5373\u5e73\u8861\u56e0\u5b50\u4e3a -1\u30010 \u6216 1&#xff09;&#xff1b;<\/li>\n<li>\u5982\u679c\u5e73\u8861\u56e0\u5b50\u8d85\u51fa\u8303\u56f4&#xff0c;\u6811\u5c06\u8fdb\u884c\u65cb\u8f6c\u64cd\u4f5c&#xff0c;\u5305\u62ec\u53f3\u5355\u65cb\u3001\u5de6\u5355\u65cb\u3001\u5de6\u53f3\u53cc\u65cb\u3001\u53f3\u5de6\u53cc\u65cb\u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7ea2\u9ed1\u6811 \u5219\u5728\u5176\u57fa\u7840\u4e0a\u5f15\u5165\u4e86\u4ee5\u4e0b\u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u6bcf\u4e2a\u8282\u70b9\u5fc5\u987b\u662f\u7ea2\u8272\u6216\u9ed1\u8272&#xff1b;<\/li>\n<li>\u6839\u8282\u70b9\u5fc5\u987b\u662f\u9ed1\u8272&#xff1b;<\/li>\n<li>\u7ea2\u8272\u8282\u70b9\u7684\u5b50\u8282\u70b9\u5fc5\u987b\u662f\u9ed1\u8272&#xff1b;<\/li>\n<li>\u4ece\u4efb\u4f55\u8282\u70b9\u5230\u5176\u6240\u6709\u540e\u4ee3\u53f6\u5b50\u8282\u70b9\u7684\u8def\u5f84\u4e0a&#xff0c;\u5fc5\u987b\u6709\u76f8\u540c\u6570\u91cf\u7684\u9ed1\u8272\u8282\u70b9&#xff1b;<\/li>\n<li>\u53f6\u5b50\u8282\u70b9&#xff08;\u7a7a\u8282\u70b9&#xff09;\u5fc5\u987b\u662f\u9ed1\u8272\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u867d\u7136\u7ea2\u9ed1\u6811\u5728\u65cb\u8f6c\u64cd\u4f5c\u7684\u9891\u7387\u4e0a\u4f4e\u4e8e AVL \u6811&#xff0c;\u4f46\u5b83\u901a\u8fc7\u8f83\u5c11\u7684\u65cb\u8f6c\u4fdd\u6301\u6811\u7684\u63a5\u8fd1\u5e73\u8861\u72b6\u6001&#xff0c;\u80fd\u591f\u786e\u4fdd\u826f\u597d\u7684\u6027\u80fd\u3002<\/p>\n<p><span style=\"color:#0d0016\">Map \u4e0e Set \u7684\u5e95\u5c42\u5b9e\u73b0<\/span><\/p>\n<p>\u7531\u4e8e Map \u548c Set \u5927\u591a\u7528\u4e8e\u9ad8\u6548\u68c0\u7d22&#xff0c;\u6211\u4eec\u9009\u62e9\u4f7f\u7528 \u7ea2\u9ed1\u6811 \u6765\u5b9e\u73b0\u5b83\u4eec\u7684\u5e95\u5c42\u7ed3\u6784\u3002\u7ea2\u9ed1\u6811\u80fd\u591f\u5728\u4fdd\u8bc1\u76f8\u5bf9\u5e73\u8861\u7684\u540c\u65f6&#xff0c;\u786e\u4fdd\u64cd\u4f5c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(log n)&#xff0c;\u975e\u5e38\u9002\u5408\u7528\u4e8e\u5904\u7406\u5927\u91cf\u7684\u952e\u503c\u5bf9\u6570\u636e\u3002<\/p>\n<p><span style=\"color:#0d0016\">\u5c01\u88c5\u524d\u7684\u8fed\u4ee3\u5668\u5b9e\u73b0<\/span><\/p>\n<p>\u5728\u5c01\u88c5 Map \u548c Set \u4e4b\u524d&#xff0c;\u6211\u4eec\u9700\u8981\u5148\u5b9e\u73b0\u4e00\u4e2a\u5173\u952e\u7684\u7ec4\u4ef6&#xff1a;\u8fed\u4ee3\u5668\u3002\u8fed\u4ee3\u5668\u662f\u904d\u5386\u5bb9\u5668\u5185\u5143\u7d20\u7684\u6838\u5fc3\u5de5\u5177&#xff0c;\u5b83\u63d0\u4f9b\u4e86\u8bbf\u95ee\u548c\u64cd\u4f5c\u5143\u7d20\u7684\u65b9\u5f0f&#xff0c;\u5e76\u4e3a\u6211\u4eec\u540e\u7eed\u7684\u5c01\u88c5\u5de5\u4f5c\u5960\u5b9a\u4e86\u57fa\u7840\u3002<\/p>\n<h2 id=\"2%E3%80%81%E8%BF%AD%E4%BB%A3%E5%99%A8%E6%9C%BA%E5%88%B6%E2%80%94%E2%80%94RBTree%20%E8%BF%AD%E4%BB%A3%E5%99%A8%E7%9A%84%E6%9E%B6%E6%9E%84%E4%B8%8E%E5%B7%A5%E7%A8%8B%E5%AE%9E%E7%8E%B0\">2\u3001\u8fed\u4ee3\u5668\u673a\u5236\u2014\u2014RBTree \u8fed\u4ee3\u5668\u7684\u67b6\u6784\u4e0e\u5de5\u7a0b\u5b9e\u73b0<\/h2>\n<p>\u8fed\u4ee3\u5668\u662f\u5bb9\u5668\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u7ec4\u6210\u90e8\u5206&#xff0c;\u5b83\u4f7f\u5f97\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u904d\u5386\u6570\u636e\u3002\u5728 \u7ea2\u9ed1\u6811 \u7684\u5b9e\u73b0\u4e2d&#xff0c;\u589e\u52a0\u8fed\u4ee3\u5668\u652f\u6301\u4e0d\u4ec5\u4ec5\u662f\u4e3a\u4e86\u63d0\u4f9b\u904d\u5386\u7684\u4fbf\u5229&#xff0c;\u66f4\u662f\u4e3a\u4e86\u4f7f\u5f97\u7ea2\u9ed1\u6811\u80fd\u591f\u7b26\u5408\u73b0\u4ee3 C&#043;&#043; \u6cdb\u578b\u7f16\u7a0b\u7684\u8981\u6c42&#xff0c;\u9075\u5faa STL \u4e2d\u5bf9\u8fed\u4ee3\u5668\u7684\u4e25\u683c\u89c4\u8303\u3002<\/p>\n<p>\u9996\u5148&#xff0c;\u8003\u8651\u5230\u8fed\u4ee3\u5668\u7684\u8bbe\u8ba1&#xff0c;\u6211\u4eec\u9700\u8981\u89e3\u51b3\u51e0\u4e2a\u5173\u952e\u95ee\u9898&#xff1a;<\/p>\n<li>\n<p>\u6cdb\u578b\u7f16\u7a0b\u4e0e\u8fed\u4ee3\u5668\u6846\u67b6 \u8fed\u4ee3\u5668\u7684\u5b9e\u73b0\u8981\u652f\u6301\u6cdb\u578b\u7f16\u7a0b&#xff0c;\u56e0\u6b64\u9700\u8981\u8003\u8651\u5176\u63a5\u53e3\u8bbe\u8ba1&#xff0c;\u786e\u4fdd\u5b83\u80fd\u9002\u5e94\u4e0d\u540c\u7c7b\u578b\u7684\u5bb9\u5668\u7ed3\u6784\u3002\u5177\u4f53\u800c\u8a00&#xff0c;\u6211\u4eec\u9700\u8981\u5b9e\u73b0\u4e00\u4e2a\u9002\u7528\u4e8e\u7ea2\u9ed1\u6811\u7684\u8fed\u4ee3\u5668\u6a21\u677f&#xff0c;\u652f\u6301\u4e0d\u540c\u7c7b\u578b\u7684\u952e\u503c\u5bf9\u5bb9\u5668\u3002<\/p>\n<\/li>\n<li>\n<p>begin() \u4e0e end() \u7684\u8bbe\u8ba1STL \u660e\u786e\u89c4\u5b9a\u4e86 begin() \u4e0e end() \u65b9\u6cd5\u5206\u522b\u4ee3\u8868\u5bb9\u5668\u7684\u8d77\u59cb\u4f4d\u7f6e\u548c\u7ed3\u675f\u4f4d\u7f6e&#xff0c;\u4e14\u662f\u524d\u95ed\u540e\u5f00\u7684\u533a\u95f4\u3002\u5728\u7ea2\u9ed1\u6811\u7684\u60c5\u51b5\u4e0b&#xff0c;\u7531\u4e8e\u5176\u8282\u70b9\u7ecf\u8fc7\u4e2d\u5e8f\u904d\u5386\u662f\u6709\u5e8f\u7684&#xff0c;begin() \u5e94\u8be5\u6307\u5411\u6811\u7684\u6700\u5c0f\u8282\u70b9&#xff08;\u5373\u6700\u5de6\u4fa7\u8282\u70b9&#xff09;&#xff0c;end() \u5219\u5e94\u6307\u5411\u4e00\u4e2a\u7a7a\u8282\u70b9&#xff0c;\u5373\u6700\u5927\u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u4f4d\u7f6e&#xff08;\u4e3a\u4e86\u7b80\u5316\u8bbe\u8ba1&#xff0c;\u53ef\u4ee5\u8bbe\u4e3a nullptr&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>operator&#043;&#043;() \u548c operator&#8211;() \u7684\u5b9e\u73b0 \u5728\u8fed\u4ee3\u5668\u7684\u64cd\u4f5c\u7b26 &#043;&#043; \u548c &#8212; \u5b9e\u73b0\u4e0a&#xff0c;\u9700\u8981\u9075\u5faa\u7ea2\u9ed1\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u987a\u5e8f\u3002\u4e0e\u94fe\u8868\u6216\u6570\u7ec4\u4e0d\u540c&#xff0c;\u7ea2\u9ed1\u6811\u7684\u8282\u70b9\u5e76\u4e0d\u662f\u987a\u5e8f\u6392\u5217\u7684&#xff0c;\u56e0\u6b64\u7b80\u5355\u7684\u6307\u9488\u9012\u589e\u6216\u9012\u51cf\u64cd\u4f5c\u65e0\u6cd5\u6ee1\u8db3\u9700\u6c42\u3002\u6211\u4eec\u9700\u8981\u901a\u8fc7\u6811\u7684\u7ed3\u6784\u6765\u786e\u5b9a\u201c\u4e0b\u4e00\u4e2a\u201d\u6216\u201c\u4e0a\u4e00\u4e2a\u201d\u8282\u70b9\u7684\u4f4d\u7f6e&#xff0c;\u8fd9\u901a\u5e38\u901a\u8fc7\u65cb\u8f6c\u548c\u7236\u8282\u70b9\u5f15\u7528\u6765\u5b9e\u73b0\u3002<\/p>\n<\/li>\n<h4 id=\"%E8%BF%AD%E4%BB%A3%E5%99%A8%E6%A1%86%E6%9E%B6%E7%9A%84%E6%90%AD%E5%BB%BA\">\u8fed\u4ee3\u5668\u6846\u67b6\u7684\u642d\u5efa<\/h4>\n<p>\u5728\u786e\u5b9a\u4e86\u8fed\u4ee3\u5668\u7684\u9700\u6c42\u540e&#xff0c;\u63a5\u4e0b\u6765\u6211\u4eec\u53ef\u4ee5\u7740\u624b\u642d\u5efa\u8fed\u4ee3\u5668\u6846\u67b6\u3002\u8be5\u6846\u67b6\u9700\u8981\u652f\u6301\u4ee5\u4e0b\u529f\u80fd&#xff1a;<\/p>\n<ul>\n<li>\u6784\u9020\u4e0e\u9500\u6bc1&#xff1a;\u652f\u6301\u7ea2\u9ed1\u6811\u8fed\u4ee3\u5668\u7684\u6784\u9020\u4e0e\u6790\u6784\u3002<\/li>\n<li>\u6307\u9488\u8bbf\u95ee&#xff1a;\u63d0\u4f9b\u5bf9\u5f53\u524d\u8282\u70b9\u7684\u8bbf\u95ee\u80fd\u529b&#xff0c;\u901a\u5e38\u901a\u8fc7\u89e3\u5f15\u7528\u64cd\u4f5c\u7b26 * \u548c\u6210\u5458\u8bbf\u95ee\u64cd\u4f5c\u7b26 -&gt; \u6765\u5b9e\u73b0\u3002<\/li>\n<li>\u524d\u8fdb\u4e0e\u540e\u9000&#xff1a;\u901a\u8fc7 &#043;&#043; \u548c &#8212; \u64cd\u4f5c\u7b26\u6765\u652f\u6301\u8fed\u4ee3\u5668\u7684\u524d\u8fdb\u4e0e\u540e\u9000&#xff0c;\u786e\u4fdd\u5176\u7b26\u5408\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u89c4\u5219\u3002<\/li>\n<li>\u6bd4\u8f83\u64cd\u4f5c&#xff1a;\u652f\u6301 &#061;&#061; \u548c !&#061; \u6bd4\u8f83\u64cd\u4f5c&#xff0c;\u5224\u65ad\u4e24\u4e2a\u8fed\u4ee3\u5668\u662f\u5426\u6307\u5411\u540c\u4e00\u8282\u70b9\u3002<\/li>\n<\/ul>\n<p>\/\/ \u8fed\u4ee3\u5668<br \/>\n\/\/ T \u8868\u793a\u6570\u636e\u7c7b\u578b Ref\u4e3a\u5f15\u7528 Ptr\u4e3a\u6307\u9488<br \/>\ntemplate&lt;class T,class Ptr,class Ref&gt;<br \/>\nstruct RBTreeIterator<br \/>\n{<br \/>\n\/\/\u4e3a\u4e86\u65b9\u4fbf\u8c03\u7528&#xff0c;\u6211\u4eec\u91cd\u547d\u540d\u4e00\u4e0b<br \/>\ntypedef RBTreeNode&lt;T&gt; Node;<br \/>\ntypedef _RBTreeIterator&lt;T, Ref, Ptr&gt; Self;<\/p>\n<p>\/\/\u5185\u90e8\u662f\u8282\u70b9\u6307\u9488<br \/>\nNode* _node;<br \/>\n_RBTreeIterator(Node* node)<br \/>\n:_node(node)<br \/>\n{}<\/p>\n<p>\/\/\u4e24\u79cd\u6307\u5411\u65b9\u5f0f<br \/>\nRef operator*()<br \/>\n{<br \/>\nreturn _node-&gt;_data;<br \/>\n}<br \/>\nPtr operator&amp;()<br \/>\n{<br \/>\nreturn &amp;_node-&gt;_data;<br \/>\n}<\/p>\n<p>bool operator!&#061; (const Self&amp; s)<br \/>\n{<br \/>\nreturn _node !&#061; s._node;<br \/>\n}<br \/>\nbool operator&#061;&#061; (const Self&amp; s)<br \/>\n{<br \/>\nreturn _node &#061;&#061; s._node;<br \/>\n}<\/p>\n<p>}; <\/p>\n<h4 id=\"%E8%BF%AD%E4%BB%A3%E5%99%A8%E7%9A%84%E8%AE%BF%E9%97%AE%20%2B%2B%20%E5%92%8C%20--\">\u8fed\u4ee3\u5668\u7684\u8bbf\u95ee &#043;&#043; \u548c &#8212;<\/h4>\n<p>&#043;&#043; \u4e2d\u5e8f\u904d\u5386\u7684\u987a\u5e8f\u662f\u5148\u904d\u5386\u5de6\u8fb9\u518d\u904d\u5386\u5f53\u524d\u8282\u70b9\u6700\u540e\u662f\u53f3\u5b50\u6811\u3002<\/p>\n<p>Self&amp; operator&#043;&#043;()<br \/>\n{<br \/>\n\/\/\u9996\u5148&#xff0c;\u80fd\u8bbf\u95ee\u5230\u5f53\u524d\u8282\u70b9\u8bf4\u660e\u5de6\u5b50\u6811\u7684\u90fd\u5df2\u7ecf\u8bbf\u95ee\u8fc7\u5566 \u5de6 \u6839 \u53f3  \u4e2d\u5e8f<br \/>\n\/\/\u6240\u4ee5\u5c31\u8981\u5206\u7c7b\u8ba8\u8bba<br \/>\n\/\/\u5982\u679c\u53f3\u8fb9\u6709\u5b50\u6811,\u5c31\u8981\u53bb\u5bfb\u627e\u53f3\u5b50\u6811\u7684\u6700\u5de6\u8282\u70b9<br \/>\nif (_node-&gt;_right)<br \/>\n{<br \/>\nNode* cur &#061; _node-&gt;_right;<br \/>\nwhile (cur-&gt;_left)<br \/>\n{<br \/>\ncur &#061; cur-&gt;_left;<br \/>\n}<br \/>\n_node &#061; cur;<br \/>\n}<br \/>\n\/\/\u5982\u679c\u53f3\u8fb9\u6ca1\u6709\u5b50\u6811\u4e86&#xff0c;\u8bf4\u660e\u8be5\u8282\u70b9\u4ee5\u4e0b\u7684\u5b50\u6811\u90fd\u5df2\u904d\u5386\u5b8c&#xff0c;\u90a3\u4e48\u5c31\u8981\u5411\u4e0a\u8fdb\u884c&#043;&#043;<br \/>\n\/\/\u627e\u5230\u7956\u5148\u8282\u70b9(\u6ce8\u610f\u7956\u5148\u8282\u70b9\u53f3\u8fb9\u53ef\u80fd\u8fd8\u6ca1\u904d\u5386)<br \/>\n\/\/\u6b64\u65f6\u4e5f\u8981\u8fdb\u884c\u5206\u7c7b\u8ba8\u8bba<br \/>\nelse<br \/>\n{<br \/>\nNode* cur &#061; _node;<br \/>\nNode* parent &#061; _node-&gt;_parent;<br \/>\n\/\/ \u5982\u679c _node &#061;&#061; parent-&gt;_right<br \/>\n\/\/\u8bf4\u660eparent\u7684\u8282\u70b9\u5df2\u7ecf\u8bbf\u95ee\u8fc7\u4e86 \u9700\u8981\u5411\u4e0a\u904d\u5386 \u627e\u5230\u6ca1\u6709\u8bbf\u95ee\u7684 \u53ef\u80fd\u4e00\u76f4\u5411\u4e0a \u5bfc\u81f4 parent \u7a7a \u6240\u4ee5\u5224\u65ad\u4e00\u4e0b<br \/>\nwhile (parent &amp;&amp; cur &#061;&#061; parent-&gt;_right)<br \/>\n{<br \/>\ncur &#061; parent;<br \/>\nparent &#061; cur-&gt;_parent;<br \/>\n}<br \/>\n_node &#061; parent;<br \/>\n}<br \/>\nreturn *this;<br \/>\n} <\/p>\n<p><span style=\"color:#0d0016\">\u9002\u5ea6\u7ed3\u5408\u56fe\u50cf\u5206\u6790&#xff0c;\u8fd8\u662f\u8981\u9075\u5faa\u5de6\u6839\u53f3\u7684\u6838\u5fc3\u601d\u7ef4\u51b3\u5b9a\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u4f4d\u7f6e<\/span><\/p>\n<p><span style=\"color:#0d0016\">&#8212; \u5012\u4e2d\u5e8f\u904d\u5386 \u53f3 \u6839 \u5de6 \u903b\u8f91\u53d6\u53cd\u5373\u53ef\u00a0<\/span><\/p>\n<p>Self&amp; operator&#8211;()<br \/>\n{<br \/>\nif (_node &#061;&#061; nullptr) \/\/ end()<br \/>\n{<br \/>\n\/\/ &#8211;end()&#xff0c;\u7279\u6b8a\u5904\u7406&#xff0c;\u8d70\u5230\u4e2d\u5e8f\u6700\u540e\u2f00\u4e2a\u7ed3\u70b9&#xff0c;\u6574\u68f5\u6811\u7684\u6700\u53f3\u7ed3\u70b9<br \/>\nNode* rightMost &#061; _root;<br \/>\nwhile (rightMost &amp;&amp; rightMost-&gt;_right)<br \/>\n{<br \/>\nrightMost &#061; rightMost-&gt;_right;<br \/>\n}<br \/>\n_node &#061; rightMost;<br \/>\n}<br \/>\n\/\/\u9996\u5148&#xff0c;\u80fd\u8bbf\u95ee\u5230\u5f53\u524d\u8282\u70b9\u8bf4\u660e\u53f3\u5b50\u6811\u7684\u90fd\u5df2\u7ecf\u8bbf\u95ee\u8fc7\u5566 \u53f3 \u6839 \u5de6  \u5012\u4e2d\u5e8f<br \/>\n\/\/\u6240\u4ee5\u5c31\u8981\u5206\u7c7b\u8ba8\u8bba<br \/>\n\/\/\u5982\u679c\u5de6\u8fb9\u6709\u5b50\u6811,\u5c31\u8981\u53bb\u5bfb\u627e\u5de6\u5b50\u6811\u7684\u6700\u53f3\u8282\u70b9<br \/>\nelse if (_node-&gt;_left)<br \/>\n{<br \/>\nNode* cur &#061; _node-&gt;_left;<br \/>\nwhile (cur-&gt;_right)<br \/>\n{<br \/>\ncur &#061; cur-&gt;_right;<br \/>\n}<br \/>\n_node &#061; cur;<br \/>\n}<br \/>\n\/\/\u5982\u679c\u5de6\u8fb9\u6ca1\u6709\u5b50\u6811\u4e86&#xff0c;\u8bf4\u660e\u8be5\u8282\u70b9\u4ee5\u4e0b\u7684\u5b50\u6811\u90fd\u5df2\u904d\u5386\u5b8c&#xff0c;\u90a3\u4e48\u5c31\u8981\u5411\u4e0a\u8fdb\u884c&#8211;<br \/>\n\/\/\u627e\u5230\u7956\u5148\u8282\u70b9(\u6ce8\u610f\u7956\u5148\u8282\u5de6\u8fb9\u53ef\u80fd\u8fd8\u6ca1\u904d\u5386)<br \/>\n\/\/\u6b64\u65f6\u4e5f\u8981\u8fdb\u884c\u5206\u7c7b\u8ba8\u8bba<br \/>\nelse<br \/>\n{<br \/>\nNode* cur &#061; _node;<br \/>\nNode* parent &#061; _node-&gt;_parent;<br \/>\n\/\/ \u5982\u679c _node &#061;&#061; parent-&gt;_left<br \/>\n\/\/\u8bf4\u660eparent\u7684\u8282\u70b9\u5df2\u7ecf\u8bbf\u95ee\u8fc7\u4e86 \u9700\u8981\u5411\u4e0a\u904d\u5386 \u627e\u5230\u6ca1\u6709\u8bbf\u95ee\u7684 \u53ef\u80fd\u4e00\u76f4\u5411\u4e0a \u5bfc\u81f4 parent \u7a7a \u6240\u4ee5\u5224\u65ad\u4e00\u4e0b<br \/>\nwhile (parent &amp;&amp; cur &#061;&#061; parent-&gt;_left)<br \/>\n{<br \/>\ncur &#061; parent;<br \/>\nparent &#061; cur-&gt;_parent;<br \/>\n}<br \/>\n_node &#061; parent;<br \/>\n}<br \/>\nreturn *this;<br \/>\n}<\/p>\n<p>\u8fd9\u91cc\u7279\u6b8a\u60c5\u51b5\u662f\u56e0\u4e3a \u6211\u4eec\u8bbe\u7f6e\u7684\u5bb9\u5668\u8fed\u4ee3\u5668 end&#xff08;&#xff09; \u4e3a\u7a7a\u6307\u9488 &#xff08;STTL\u5e93\u662f\u52a0\u4e86\u4e2a\u54e8\u5175\u4f4d\u8282\u70b9&#xff09;\u4e0d\u53ef\u4ee5\u518d\u8bbf\u95ee\u4e86\u6240\u4ee5\u7279\u6b8a\u5904\u7406\u4e00\u4e0b<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"855\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250620220604-6855db4c94bcc.png\" width=\"1200\" \/><\/p>\n<h2 id=\"3%E3%80%81%E9%AB%98%E7%BA%A7%E5%AE%B9%E5%99%A8%E8%AE%BE%E8%AE%A1%E2%80%94%E2%80%94Map%20%E4%B8%8E%20Set%20%E7%9A%84%E6%A8%A1%E5%9D%97%E5%8C%96%E5%B0%81%E8%A3%85\">3\u3001\u9ad8\u7ea7\u5bb9\u5668\u8bbe\u8ba1\u2014\u2014Map \u4e0e Set \u7684\u6a21\u5757\u5316\u5c01\u88c5<\/h2>\n<h3 id=\"3.1%20%E6%B3%9B%E5%9E%8B%E6%94%AF%E6%8C%81%E5%A2%9E%E5%BC%BA%E2%80%94%E2%80%94RBTree%20%E6%A8%A1%E6%9D%BF%E5%8F%82%E6%95%B0%E8%AE%BE%E8%AE%A1%E4%BC%98%E5%8C%96\">3.1 \u6cdb\u578b\u652f\u6301\u589e\u5f3a\u2014\u2014RBTree \u6a21\u677f\u53c2\u6570\u8bbe\u8ba1\u4f18\u5316<\/h3>\n<p>\u6211\u4eec\u5148\u6765\u770b\u4e4b\u524d\u5199\u7684\u7ea2\u9ed1\u6811\u7684\u8282\u70b9\u4ee3\u7801&#xff1a;<\/p>\n<p>\/\/ \u8282\u70b9\u7ed3\u6784\u4f53<br \/>\ntemplate&lt;class K, class V&gt;<br \/>\nstruct RBTreeNode<br \/>\n{<br \/>\nRBTreeNode&lt;K, V&gt;* _left;<br \/>\nRBTreeNode&lt;K, V&gt;* _right;<br \/>\nRBTreeNode&lt;K, V&gt;* _parent;<\/p>\n<p>pair&lt;K, V&gt; _kv;<br \/>\ncolor _col;<br \/>\nRBTreeNode(pair&lt;K, V&gt; kv)<br \/>\n:_left(nullptr),<br \/>\n_right(nullptr),<br \/>\n_parent(nullptr),<br \/>\n_kv(kv)<br \/>\n{}<\/p>\n<p>};<\/p>\n<p>\u5728\u5b9e\u73b0 Map \u548c Set \u7684\u5c01\u88c5\u65f6&#xff0c;\u6211\u4eec\u53d1\u73b0&#xff0c;\u5f53\u524d\u7684\u8bbe\u8ba1\u4f7f\u5f97\u6bcf\u4e2a\u7ea2\u9ed1\u6811\u7684\u8282\u70b9\u90fd\u5b58\u50a8\u4e86\u4e00\u4e2a\u56fa\u5b9a\u7684\u6570\u636e\u7c7b\u578b pair&lt;K, V&gt;\u3002\u8fd9\u79cd\u505a\u6cd5\u867d\u7136\u5bf9 Map \u7684\u5b9e\u73b0\u6765\u8bf4\u975e\u5e38\u76f4\u63a5&#xff0c;\u4f46\u5f53\u6211\u4eec\u5c1d\u8bd5\u4e3a Set \u5c01\u88c5\u65f6&#xff0c;\u95ee\u9898\u5c31\u663e\u73b0\u51fa\u6765\u4e86&#xff1a;Set \u4e2d\u7684\u8282\u70b9\u53ea\u9700\u8981\u5b58\u50a8\u952e K&#xff0c;\u800c\u4e0d\u662f\u952e\u503c\u5bf9 pair&lt;K, V&gt;\u3002\u8fd9\u610f\u5473\u7740\u5982\u679c\u6211\u4eec\u7167\u8fd9\u79cd\u65b9\u5f0f\u5b9e\u73b0 Set&#xff0c;\u6211\u4eec\u5c31\u4e0d\u5f97\u4e0d\u91cd\u590d\u7f16\u5199\u4e00\u4efd\u7c7b\u4f3c\u7684\u7ea2\u9ed1\u6811\u4ee3\u7801\u6765\u5904\u7406\u4e0d\u540c\u7684\u6570\u636e\u7ed3\u6784\u3002\u8fd9\u6837\u4e0d\u4ec5\u589e\u52a0\u4e86\u4ee3\u7801\u7684\u5197\u4f59&#xff0c;\u4e5f\u8ba9\u4ee3\u7801\u7684\u7ef4\u62a4\u53d8\u5f97\u4e0d\u591f\u4f18\u96c5\u3002<\/p>\n<p>\u4e3a\u4e86\u66f4\u597d\u5730\u5c01\u88c5 Map \u548c Set&#xff0c;\u6211\u4eec\u53ef\u4ee5\u501f\u9274 STL \u6e90\u7801\u4e2d\u7684\u8bbe\u8ba1\u7406\u5ff5\u3002STL \u4e2d\u901a\u8fc7 \u6a21\u677f\u7f16\u7a0b \u548c \u7c7b\u578b\u7279\u5316 \u7684\u65b9\u5f0f&#xff0c;\u4f7f\u5f97\u540c\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u80fd\u591f\u652f\u6301\u4e0d\u540c\u7c7b\u578b\u7684\u5bb9\u5668&#xff0c;\u800c\u4e0d\u9700\u8981\u91cd\u590d\u7f16\u5199\u4ee3\u7801\u3002\u8fd9\u79cd\u8bbe\u8ba1\u4e0d\u4ec5\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u590d\u7528\u6027&#xff0c;\u8fd8\u4f7f\u5f97\u5bb9\u5668\u80fd\u591f\u7075\u6d3b\u5730\u5904\u7406\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p><span style=\"color:#0d0016\">STL \u7684\u8bbe\u8ba1\u601d\u8def<\/span><\/p>\n<p>\u5728 STL \u4e2d&#xff0c;Map \u548c Set \u90fd\u662f\u901a\u8fc7\u5e95\u5c42\u7ea2\u9ed1\u6811&#xff08;\u6216\u5176\u4ed6\u5e73\u8861\u6811&#xff09;\u6765\u5b9e\u73b0\u7684&#xff0c;\u4f46\u5b83\u4eec\u6709\u4e0d\u540c\u7684\u7ed3\u6784\u548c\u9700\u6c42&#xff1a;<\/p>\n<ul>\n<li>Map \u662f\u4e00\u4e2a\u952e\u503c\u5bf9\u5bb9\u5668&#xff0c;\u8282\u70b9\u5b58\u50a8 pair&lt;K, V&gt;&#xff1b;<\/li>\n<li>Set \u662f\u4e00\u4e2a\u53ea\u5b58\u50a8\u952e\u7684\u5bb9\u5668&#xff0c;\u8282\u70b9\u53ea\u9700\u8981\u5b58\u50a8 K\u3002<\/li>\n<\/ul>\n<p>\u7136\u800c&#xff0c;\u5c3d\u7ba1\u5b83\u4eec\u7684\u6570\u636e\u5b58\u50a8\u7ed3\u6784\u4e0d\u540c&#xff0c;STL \u5e76\u6ca1\u6709\u4e3a Map \u548c Set \u5206\u522b\u5199\u4e24\u4efd\u5b8c\u5168\u4e0d\u540c\u7684\u7ea2\u9ed1\u6811\u4ee3\u7801\u3002\u76f8\u53cd&#xff0c;STL \u901a\u8fc7\u5de7\u5999\u7684\u6a21\u677f\u8bbe\u8ba1&#xff0c;\u4f7f\u5f97\u540c\u4e00\u4e2a\u7ea2\u9ed1\u6811\u5b9e\u73b0\u80fd\u591f\u6839\u636e\u9700\u6c42\u7075\u6d3b\u5b58\u50a8\u952e\u503c\u5bf9\u6216\u8005\u4ec5\u5b58\u50a8\u952e\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1200\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250620220604-6855db4cec139.png\" width=\"1200\" \/><\/p>\n<p>\u53ef\u4ee5\u770b\u51fa&#xff0c;STL \u6e90\u7801\u4e2d\u7684\u8bbe\u8ba1\u5de7\u5999\u5730\u5229\u7528\u4e86\u6a21\u677f\u7f16\u7a0b&#xff0c;\u6210\u529f\u5730\u5b9e\u73b0\u4e86 Map \u548c Set \u7684\u7edf\u4e00\u5c01\u88c5&#xff0c;\u907f\u514d\u4e86\u4ee3\u7801\u5197\u4f59\u3002<\/p>\n<h4 id=\"STL%E8%AE%BE%E8%AE%A1%E6%80%9D%E8%B7%AF%E8%A7%A3%E6%9E%90\">STL\u8bbe\u8ba1\u601d\u8def\u89e3\u6790<\/h4>\n<p>\u9996\u5148&#xff0c;\u6700\u5e95\u5c42\u7684\u7ea2\u9ed1\u6811\u8282\u70b9\u7ed3\u6784\u4f53\u53ea\u4f7f\u7528\u4e86\u4e00\u4e2a\u6a21\u677f\u53c2\u6570 Value&#xff0c;\u8be5\u53c2\u6570\u51b3\u5b9a\u4e86\u8282\u70b9\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u7c7b\u578b\u3002\u4e0a\u5c42\u7684\u7ea2\u9ed1\u6811\u6839\u636e\u63d0\u4f9b\u7684 Value \u7c7b\u578b\u6765\u9009\u62e9\u5177\u4f53\u7684\u6570\u636e\u5b58\u50a8\u7ed3\u6784\u3002\u8fd9\u6837&#xff0c;\u7ea2\u9ed1\u6811\u7684\u5e95\u5c42\u5b9e\u73b0\u4e0d\u9700\u8981\u533a\u5206 Map \u548c Set&#xff0c;\u800c\u662f\u901a\u8fc7\u6a21\u677f\u53c2\u6570 Value \u6765\u7075\u6d3b\u9002\u5e94\u4e0d\u540c\u9700\u6c42\u3002<\/p>\n<h4 id=\"%E7%BA%A2%E9%BB%91%E6%A0%91%E7%9A%84%E5%85%B3%E9%94%AE%E6%A8%A1%E6%9D%BF%E5%8F%82%E6%95%B0\">\u7ea2\u9ed1\u6811\u7684\u5173\u952e\u6a21\u677f\u53c2\u6570<\/h4>\n<p>\u5728\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0\u4e2d&#xff0c;\u5b58\u5728\u4e09\u4e2a\u5173\u952e\u7684\u6a21\u677f\u53c2\u6570&#xff1a;<\/p>\n<li>Key&#xff1a;\u8868\u793a\u952e\u7684\u7c7b\u578b&#xff0c;\u4e3b\u8981\u7528\u4e8e\u67e5\u627e\u64cd\u4f5c&#xff08;\u5982 Find \u51fd\u6570&#xff09;\u3002\u901a\u8fc7 Key&#xff0c;\u7ea2\u9ed1\u6811\u53ef\u4ee5\u9ad8\u6548\u5730\u5b9a\u4f4d\u67d0\u4e2a\u8282\u70b9\u662f\u5426\u5b58\u5728\u3002<\/li>\n<li>Value&#xff1a;\u8868\u793a\u5b58\u50a8\u7684\u6570\u636e\u7c7b\u578b\u3002\u5728 Map \u4e2d&#xff0c;Value \u662f pair&lt;K, V&gt;&#xff0c;\u800c\u5728 Set \u4e2d&#xff0c;Value \u5219\u53ea\u6709\u952e K\u3002<\/li>\n<li>KeyOfValue&#xff1a;\u8fd9\u662f\u4e00\u4e2a\u4eff\u51fd\u6570&#xff0c;\u7528\u4e8e\u4ece Value \u4e2d\u63d0\u53d6 Key\u3002\u8be5\u4eff\u51fd\u6570\u5728\u5f88\u591a\u64cd\u4f5c\u4e2d\u90fd\u975e\u5e38\u91cd\u8981&#xff0c;\u7279\u522b\u662f\u5728\u67e5\u627e\u64cd\u4f5c\u4e2d&#xff0c;\u5b83\u80fd\u5e2e\u52a9\u6211\u4eec\u4ece Value \u4e2d\u63d0\u53d6\u51fa Key&#xff0c;\u7528\u4e8e\u6bd4\u8f83\u548c\u5b9a\u4f4d\u3002<\/li>\n<h4 id=\"%E7%BB%9F%E4%B8%80%E5%B0%81%E8%A3%85%EF%BC%9A%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%20Map%20%E4%B8%8E%20Set%20%E7%9A%84%E5%85%B1%E4%BA%AB%E5%BA%95%E5%B1%82%E7%BA%A2%E9%BB%91%E6%A0%91\">\u7edf\u4e00\u5c01\u88c5&#xff1a;\u5982\u4f55\u5b9e\u73b0 Map \u4e0e Set \u7684\u5171\u4eab\u5e95\u5c42\u7ea2\u9ed1\u6811<\/h4>\n<p>\u901a\u8fc7\u5de7\u5999\u7684\u6a21\u677f\u8bbe\u8ba1&#xff0c;\u7ea2\u9ed1\u6811\u5e95\u5c42\u5b9e\u73b0\u53ef\u4ee5\u6839\u636e\u4e0d\u540c\u7684\u9700\u6c42\u4f7f\u7528\u4e0d\u540c\u7684\u6570\u636e\u7ed3\u6784\u6765\u5b58\u50a8&#xff1a;<\/p>\n<ul>\n<li>\u5bf9\u4e8e Map&#xff0c;\u5e95\u5c42\u7ea2\u9ed1\u6811\u5c06 Key \u548c pair&lt;K, V&gt; \u4f5c\u4e3a\u6a21\u677f\u53c2\u6570\u4f20\u5165\u3002Key \u7528\u4e8e\u67e5\u627e\u64cd\u4f5c&#xff0c;\u800c Value \u5219\u662f pair&lt;K, V&gt;&#xff0c;\u5373\u5305\u542b\u952e\u548c\u503c\u7684\u7ed3\u6784\u3002\u00a0<\/li>\n<li><span style=\"color:#ff0000\">map:\u5c31\u4f20\u7ed9\u7ea2\u9ed1\u6811&lt;K , pair&lt;K,V&gt; &#8230;&gt;<\/span><\/li>\n<li>\u5bf9\u4e8e Set&#xff0c;\u7ea2\u9ed1\u6811\u53ea\u9700\u8981 Key \u4f5c\u4e3a\u6a21\u677f\u53c2\u6570&#xff0c;\u56e0\u4e3a Set \u53ea\u5173\u5fc3\u5b58\u50a8\u952e K&#xff0c;\u65e0\u9700\u5b58\u50a8\u503c&#xff0c;\u4f46\u662f\u8fd9\u91cc\u7ea2\u9ed1\u6811\u7684\u524d\u4e24\u4e2a\u6a21\u677f\u53c2\u6570\u90fd\u9700\u8981\u4f20K\u3002<\/li>\n<li><span style=\"color:#ff0000\">set: \u5c31\u4f20\u7ed9\u7ea2\u9ed1\u6811&lt;K , K &#8230;&gt;<\/span><\/li>\n<\/ul>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f&#xff0c;\u5c3d\u7ba1 Map \u548c Set \u7684\u6a21\u677f\u53c2\u6570\u4e0d\u540c&#xff08;\u5206\u522b\u662f pair&lt;K, V&gt; \u548c K&#xff09;&#xff0c;\u5b83\u4eec\u5374\u53ef\u4ee5\u5171\u7528\u540c\u4e00\u4efd\u5e95\u5c42\u7ea2\u9ed1\u6811\u4ee3\u7801\u3002\u8fd9\u79cd\u8bbe\u8ba1\u4e0d\u4ec5\u907f\u514d\u4e86\u4ee3\u7801\u91cd\u590d&#xff0c;\u4e5f\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u7075\u6d3b\u6027\u3002<\/p>\n<p>\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n\/\/&#8212;&#8212;&#8212;&#8212;&#8212;- \u7ea2\u9ed1\u6811\u5b9e\u73b0 &#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n\/\/&#8212;&#8212;&#8211; \u9002\u914dmap \u4e0e set \u7684\u8fdb\u9636\u7248\u672c &#8212;&#8212;&#8212;&#8211;<br \/>\n\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>enum color<br \/>\n{<br \/>\nBlack,<br \/>\nRed<br \/>\n};<br \/>\n\/\/ \u8282\u70b9\u7ed3\u6784\u4f53<br \/>\ntemplate&lt;class T&gt;<br \/>\nstruct RBTreeNode<br \/>\n{<br \/>\nRBTreeNode&lt;T&gt;* _left;<br \/>\nRBTreeNode&lt;T&gt;* _right;<br \/>\nRBTreeNode&lt;T&gt;* _parent;<\/p>\n<p>T _data;<br \/>\ncolor _col;<br \/>\nRBTreeNode(T data)<br \/>\n:_left(nullptr),<br \/>\n_right(nullptr),<br \/>\n_parent(nullptr),<br \/>\n_data(data),<br \/>\n_col(Red)<br \/>\n{}<\/p>\n<p>};<\/p>\n<p>\/\/\u9002\u914dmap\u4e0eset \u7684\u7248\u672c<br \/>\n\/\/ \u8fed\u4ee3\u5668<br \/>\ntemplate&lt;class T , class Ref , class Ptr&gt;<br \/>\nstruct _RBTreeIterator<br \/>\n{<br \/>\ntypedef RBTreeNode&lt;T&gt; Node;<br \/>\ntypedef _RBTreeIterator&lt;T, Ref, Ptr&gt; Self;<\/p>\n<p>Node* _node;<br \/>\n_RBTreeIterator(Node* node)<br \/>\n:_node(node)<br \/>\n{}<\/p>\n<p>Ref operator*()<br \/>\n{<br \/>\nreturn _node-&gt;_data;<br \/>\n}<br \/>\nPtr operator&amp;()<br \/>\n{<br \/>\nreturn &amp;_node-&gt;_data;<br \/>\n}<br \/>\nbool operator!&#061; (const Self&amp; s)<br \/>\n{<br \/>\nreturn _node !&#061; s._node;<br \/>\n}<br \/>\n\/\/\u8fed\u4ee3\u5668\u7684&#043;&#043; \u4e2d\u5e8f\u904d\u5386\u7684\u987a\u5e8f<br \/>\nSelf&amp; operator&#043;&#043;()<br \/>\n{<br \/>\n}<br \/>\nSelf&amp; operator&#8211;()<br \/>\n{<br \/>\n}<br \/>\n};<\/p>\n<p>\/\/K \u4e3a\u952e\u503c T \u4e3a\u50a8\u5b58\u7684\u7ed3\u6784 map\u5219\u4e3apair set\u5219\u4e3akey  KeyOfValue \u662f\u53d6\u51faKey\u7684\u65b9\u5f0f<br \/>\ntemplate&lt;class K, class T , class KeyOfValue&gt;<br \/>\nclass RBTree<br \/>\n{<br \/>\npublic:<br \/>\ntypedef _RBTreeIterator&lt;T, T&amp;, T*&gt; Iterator;<br \/>\ntypedef RBTreeNode&lt;T&gt; Node;<\/p>\n<p>Iterator begin()<br \/>\n{<\/p>\n<p>}<br \/>\nIterator end()<br \/>\n{<\/p>\n<p>}<br \/>\n\/\/\u53f3\u5355\u65cb<br \/>\nvoid RotateR(Node* parent)<br \/>\n{<br \/>\n}<br \/>\n\/\/\u5de6\u53f3\u53cc\u65cb<br \/>\nvoid RotateLR(Node* parent)<br \/>\n{<br \/>\n}<br \/>\n\/\/\u53f3\u5de6\u53cc\u65cb<br \/>\nvoid RotateRL(Node* parent)<br \/>\n{<br \/>\n}<\/p>\n<p>\/\/\u63d2\u5165\u51fd\u6570<br \/>\npair&lt;Iterator,bool&gt; 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 \/>\n\/\/return pair&lt;Iterator, bool&gt;(Iterator(_root,_root),true);<br \/>\nreturn { Iterator(_root,_root), true };<br \/>\n}<br \/>\nNode* cur &#061; _root;<br \/>\nNode* parent &#061; nullptr;<br \/>\n\/\/\u67e5\u627e\u903b\u8f91 cur \u5230\u5bf9\u5e94\u7684\u4f4d\u7f6e\u53bb<br \/>\n\/\/ KeyOfT \u53d6\u7b2c\u4e00\u4e2a\u6570\u636e\u6bd4\u8f83<br \/>\nKeyOfT kot;<br \/>\nwhile (cur)<br \/>\n{<br \/>\nif (kot(cur-&gt;_data) &lt; kot(data))<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\ncur &#061; cur-&gt;_right;<br \/>\n}<br \/>\nelse if (kot(cur-&gt;_data) &gt; kot(data))<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\ncur &#061; cur-&gt;_left;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nreturn { Iterator(cur,_root), false};<br \/>\n}<br \/>\n}<br \/>\ncur &#061; new Node(data);<br \/>\nNode* newnode &#061; cur;<br \/>\ncur-&gt;_col &#061; RED; \/\/\u65b0\u63d2\u5165\u975e\u7a7a\u8282\u70b9 \u4e3a\u7ea2\u8272<br \/>\n\/\/ \u8fde\u63a5 prev \u4e0e cur<br \/>\nif (kot(parent-&gt;_data) &gt; kot(data))<br \/>\nparent-&gt;_left &#061; cur;<br \/>\nelse<br \/>\nparent-&gt;_right &#061; cur;<br \/>\ncur-&gt;_parent &#061; parent;<\/p>\n<p>\/\/ \u7236\u4eb2\u662f\u7ea2\u8272 \u51fa\u73b0\u4e86\u8fde\u7eed\u7ea2\u8282\u70b9 \u9700\u8981\u5904\u7406 \u53ef\u80fd\u591a\u6b21\u5904\u7406 while\u5411\u4e0a\u66f4\u65b0<br \/>\nwhile (parent &amp;&amp; parent-&gt;_col &#061;&#061; RED) \/\/\u53ef\u80fd\u4e3a\u7a7a<br \/>\n{<br \/>\nNode* grandfather &#061; parent-&gt;_parent;<br \/>\nif (grandfather-&gt;_left &#061;&#061; parent)<br \/>\n{<br \/>\n\/\/   g<br \/>\n\/\/ p   u<br \/>\nNode* uncle &#061; grandfather-&gt;_right;<br \/>\n\/\/ \u53d4\u53d4\u4e0d\u4e3a\u7a7a \u4e14\u7ea2\u8272<br \/>\nif (uncle &amp;&amp; uncle-&gt;_col &#061;&#061; RED)<br \/>\n{<br \/>\n\/\/\u7236\u4eb2\u548c\u53d4\u53d4\u53d8\u9ed1 \u7237\u7237\u53d8\u7ea2 \u53d8\u8272 \u89e3\u51b3\u8fde\u7eed\u7ea2\u8272\u8282\u70b9\u5e76\u4e14\u4fdd\u8bc1 \u8def\u5f84\u9ed1\u8282\u70b9\u6570\u91cf\u4e0d\u53d8<br \/>\nparent-&gt;_col &#061; uncle-&gt;_col &#061; BLACK;<br \/>\ngrandfather-&gt;_col &#061; RED;<\/p>\n<p>\/\/\u5f80\u4e0a\u66f4\u65b0<br \/>\ncur &#061; grandfather;<br \/>\nparent &#061; cur-&gt;_parent;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (parent-&gt;_left &#061;&#061; cur) \/\/\u53f3\u5355\u65cb&#043;\u53d8\u8272<br \/>\n{\/\/     g<br \/>\n\/\/   p   u<br \/>\n\/\/ c<br \/>\nRotateR(grandfather);<br \/>\nparent-&gt;_col &#061; BLACK;<br \/>\ngrandfather-&gt;_col &#061; RED;<br \/>\n}<br \/>\nelse \/\/\u53cc\u65cb\u5904\u7406<br \/>\n{<br \/>\n\/\/     g<br \/>\n\/\/   p   u<br \/>\n\/\/    c<br \/>\nRotateLR(grandfather);<br \/>\ncur-&gt;_col &#061; BLACK;<br \/>\ngrandfather-&gt;_col &#061; RED;<br \/>\n}<br \/>\nbreak;<br \/>\n}<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n\/\/   g<br \/>\n\/\/ u   p<br \/>\nNode* uncle &#061; grandfather-&gt;_left;<br \/>\n\/\/ \u53d4\u53d4\u4e0d\u4e3a\u7a7a \u4e14\u7ea2\u8272<br \/>\nif (uncle &amp;&amp; uncle-&gt;_col &#061;&#061; RED)<br \/>\n{<br \/>\n\/\/\u7236\u4eb2\u548c\u53d4\u53d4\u53d8\u9ed1 \u7237\u7237\u53d8\u7ea2 \u53d8\u8272 \u89e3\u51b3\u8fde\u7eed\u7ea2\u8272\u8282\u70b9\u5e76\u4e14\u4fdd\u8bc1 \u8def\u5f84\u9ed1\u8282\u70b9\u6570\u91cf\u4e0d\u53d8<br \/>\nparent-&gt;_col &#061; uncle-&gt;_col &#061; BLACK;<br \/>\ngrandfather-&gt;_col &#061; RED;<\/p>\n<p>\/\/\u5f80\u4e0a\u66f4\u65b0<br \/>\ncur &#061; grandfather;<br \/>\nparent &#061; cur-&gt;_parent;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (parent-&gt;_right &#061;&#061; cur) \/\/\u5de6\u5355\u65cb&#043;\u53d8\u8272<br \/>\n{\/\/     g<br \/>\n\/\/   u   p<br \/>\n\/\/   c<br \/>\nRotateL(grandfather);<br \/>\nparent-&gt;_col &#061; BLACK;<br \/>\ngrandfather-&gt;_col &#061; RED;<br \/>\n}<br \/>\nelse \/\/\u53cc\u65cb\u5904\u7406<br \/>\n{<br \/>\n\/\/     g<br \/>\n\/\/   u   p<br \/>\n\/\/c<br \/>\nRotateRL(grandfather);<br \/>\ncur-&gt;_col &#061; BLACK;<br \/>\ngrandfather-&gt;_col &#061; RED;<br \/>\n}<br \/>\nbreak;<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n_root-&gt;_col &#061; BLACK;<br \/>\nreturn { Iterator(newnode,_root), true};<br \/>\n}<\/p>\n<p>Iterator find(const K&amp; key)<br \/>\n{<br \/>\nNode* cur &#061; _root;<br \/>\nKeyOfT kot;<br \/>\nwhile (cur)<br \/>\n{<br \/>\nif (kot(cur-&gt;_data) &lt; key)<br \/>\n{<br \/>\ncur &#061; cur-&gt;_right;<br \/>\n}<br \/>\nelse if (kot(cur-&gt;_data) &gt; key)<br \/>\n{<br \/>\ncur &#061; cur-&gt;_left;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nreturn Iterator(cur,_root);<br \/>\n}<br \/>\n}<br \/>\nreturn End();<br \/>\n}<\/p>\n<p>private:<br \/>\nvoid _IsBalance(Node* root , int num)<br \/>\n{<br \/>\n}<br \/>\nbool Check(Node* root, int blackNum, const int refNum)<br \/>\n{<br \/>\n}<\/p>\n<p>void _InOrder(Node* cur)<br \/>\n{<br \/>\n}<br \/>\nRBTreeNode&lt;T&gt;* _root &#061; nullptr;<br \/>\n};<\/p>\n<p id=\"3.1%20%E6%B3%9B%E5%9E%8B%E6%94%AF%E6%8C%81%E5%A2%9E%E5%BC%BA%E2%80%94%E2%80%94RBTree%20%E6%A8%A1%E6%9D%BF%E5%8F%82%E6%95%B0%E8%AE%BE%E8%AE%A1%E4%BC%98%E5%8C%96\"><span style=\"color:#0d0016\">\u6ce8\u610f\u6bd4\u8f83\u65b9\u5f0f\u7edf\u4e00\u6539\u6210\u7c7b\u4f3ckot(_data) &lt; kot(node.data)\u7684\u6837\u5b50\u54e6&#xff01;&#xff01;&#xff01;\u56e0\u4e3amap\u4e0eset\u7684\u53d6\u51fakey\u7684\u65b9\u5f0f\u4e0d\u540c&#xff01;&#xff01;&#xff01;<\/span><\/p>\n<h3><\/h3>\n<h3 id=\"3.2%C2%A0Set%20%E5%AE%B9%E5%99%A8%E6%9E%84%E5%BB%BA%E2%80%94%E2%80%94%E9%9D%A2%E5%90%91%E9%9B%86%E5%90%88%E6%93%8D%E4%BD%9C%E7%9A%84%E4%BC%98%E5%8C%96%E8%AE%BE%E8%AE%A1\">3.2\u00a0Set \u5bb9\u5668\u6784\u5efa\u2014\u2014\u9762\u5411\u96c6\u5408\u64cd\u4f5c\u7684\u4f18\u5316\u8bbe\u8ba1<\/h3>\n<p><span style=\"color:#0d0016\">Set \u5c01\u88c5\u7684\u5b9e\u73b0<\/span><\/p>\n<p>\u5bf9\u4e8e Set\u00a0\u5c01\u88c5&#xff0c;\u5173\u952e\u662f\u8981\u6839\u636e\u7ea2\u9ed1\u6811\u7684\u5e95\u5c42\u5b9e\u73b0\u8981\u6c42\u63d0\u4f9b\u76f8\u5e94\u7684\u6a21\u677f\u53c2\u6570\u548c\u4eff\u51fd\u6570\u3002<\/p>\n<li>\n<p>\u6a21\u677f\u53c2\u6570\u4f20\u9012&#xff1a;<\/p>\n<p> Set \u9700\u8981\u6ee1\u8db3 K \u548c V \u7684\u6a21\u677f\u53c2\u6570\u4f20\u9012\u3002K \u8868\u793a\u952e\u7684\u7c7b\u578b&#xff0c;V \u8868\u793a\u503c\u7684\u7c7b\u578b\u3002<\/li>\n<li>\n<p>\u4eff\u51fd\u6570\u5b9e\u73b0&#xff1a;<\/p>\n<p> \u6211\u4eec\u9700\u8981\u5b9e\u73b0\u4e00\u4e2a\u4eff\u51fd\u6570&#xff0c;\u7528\u4e8e\u4ece\u5b58\u50a8\u7684 \u6a21\u677f\u53c2\u6570 V\u00a0\u4e2d\u63d0\u53d6\u51fa Key\u3002\u56e0\u4e3a\u6bd4\u8f83\u903b\u8f91\u662f\u6bd4\u8f83\u952e\u503c&#xff0c;\u4f46\u662f\u5e95\u5c42\u7ea2\u9ed1\u6811\u5e76\u4e0d\u77e5\u9053T\u6a21\u677f\u53c2\u6570\u662fpair \u8fd8\u662fkey struct SetKeyOfT<br \/>\n{<br \/>\nconst K&amp; operator()(const K&amp;key)<br \/>\n{<br \/>\nreturn key;<br \/>\n}<br \/>\n}; <\/p>\n<\/li>\n<li>\n<p>\u5e95\u5c42\u7ea2\u9ed1\u6811\u7684\u5b9e\u4f8b\u5316&#xff1a;<\/p>\n<p> \u5728 Set\u00a0\u7c7b\u4e2d&#xff0c;\u6211\u4eec\u5b9e\u4f8b\u5316\u4e00\u4e2a\u5e95\u5c42\u7ea2\u9ed1\u6811&#xff0c;\u4f20\u5165\u5bf9\u5e94\u7684\u6a21\u677f\u53c2\u6570 K\u3001const K&#xff08;\u6ce8\u610f&#xff0c;\u952e\u662f\u4e0d\u53ef\u4fee\u6539\u7684&#xff0c;\u6240\u4ee5\u9700\u8981\u4f7f\u7528 const\u00a0\u6765\u786e\u4fdd\u952e\u662f\u5e38\u91cf&#xff09;&#xff0c;\u4ee5\u53ca<span style=\"color:#0d0016\"> SetOfT<\/span>\u00a0\u4eff\u51fd\u6570\u3002\u8fd9\u6837&#xff0c;\u7ea2\u9ed1\u6811\u80fd\u591f\u9002\u5e94 Set\u4e2d\u952e\u503c\u5bf9\u7684\u5b58\u50a8\u65b9\u5f0f\u3002<\/li>\n<li>\n<p>\u8fed\u4ee3\u5668\u7684\u5b9e\u73b0&#xff1a;<\/p>\n<p> \u5728 Set\u00a0\u7c7b\u4e2d&#xff0c;\u6211\u4eec\u8fd8\u9700\u8981\u5b9e\u73b0\u4e00\u4e2a\u8fed\u4ee3\u5668\u3002\u53ea\u9700\u8981\u63d0\u4f9b\u57fa\u672c\u7684 begin() \u548c end() \u63a5\u53e3&#xff0c;\u76f4\u63a5\u8c03\u7528\u5e95\u5c42\u7ea2\u9ed1\u6811\u7684\u76f8\u5173\u65b9\u6cd5\u5373\u53ef\u3002\u8fed\u4ee3\u5668\u7684\u524d\u8fdb&#xff08;&#043;&#043;&#xff09;\u548c\u540e\u9000&#xff08;&#8211;&#xff09;\u64cd\u4f5c\u4ea4\u7ed9\u5e95\u5c42\u7ea2\u9ed1\u6811\u7684\u8fed\u4ee3\u5668\u6765\u5904\u7406\u3002<\/li>\n<p>namespace xc<br \/>\n{<br \/>\ntemplate&lt;class K&gt;<br \/>\nclass set<br \/>\n{<br \/>\nstruct SetKeyOfT<br \/>\n{<br \/>\nconst K&amp; operator()(const K&amp;key)<br \/>\n{<br \/>\nreturn key;<br \/>\n}<br \/>\n};<\/p>\n<p>public:<br \/>\ntypedef typename RBTree&lt;K, const K, SetKeyOfT&gt;::Iterator iterator;<br \/>\ntypedef typename RBTree&lt;K, const K, SetKeyOfT&gt;::ConstIterator const_iterator;<\/p>\n<p>iterator begin()<br \/>\n{<br \/>\nreturn _t.Begin();<br \/>\n}<\/p>\n<p>iterator end()<br \/>\n{<br \/>\nreturn _t.End();<br \/>\n}<br \/>\nconst_iterator begin()const<br \/>\n{<br \/>\nreturn _t.Begin();<br \/>\n}<\/p>\n<p>const_iterator end()const<br \/>\n{<br \/>\nreturn _t.End();<br \/>\n}<\/p>\n<p>pair&lt;iterator,bool&gt; insert(const K&amp;key)<br \/>\n{<br \/>\nreturn _t.insert(key);<br \/>\n}<\/p>\n<p>iterator find(const K&amp; key)<br \/>\n{<br \/>\nreturn _t.find(key);<br \/>\n}<br \/>\nprivate:<br \/>\nRBTree&lt;K, const K, SetKeyOfT&gt; _t;<br \/>\n};<br \/>\n} <\/p>\n<h3 id=\"%C2%A03.3%C2%A0Map%20%E5%AE%B9%E5%99%A8%E6%9E%84%E5%BB%BA%E2%80%94%E2%80%94%E9%AB%98%E6%95%88%E9%94%AE%E5%80%BC%E5%AD%98%E5%82%A8%E7%9A%84%E5%B0%81%E8%A3%85%E5%AE%9E%E7%8E%B0\">\u00a03.3\u00a0Map \u5bb9\u5668\u6784\u5efa\u2014\u2014\u9ad8\u6548\u952e\u503c\u5b58\u50a8\u7684\u5c01\u88c5\u5b9e\u73b0<\/h3>\n<p>\u5728\u5b8c\u6210\u4e86\u7ea2\u9ed1\u6811\u7684\u6539\u8fdb\u540e&#xff0c;\u63a5\u4e0b\u6765\u7684\u6b65\u9aa4\u5c31\u76f8\u5bf9\u7b80\u5355\u4e86\u3002\u6211\u4eec\u53ea\u9700\u8981\u5728\u4e0a\u5c42\u5b9e\u73b0 Map \u548c Set \u7684\u5177\u4f53\u5c01\u88c5&#xff0c;\u8c03\u7528\u5e95\u5c42\u7ea2\u9ed1\u6811\u7684\u63a5\u53e3\u5e76\u4f20\u5165\u76f8\u5e94\u7684\u6a21\u677f\u53c2\u6570\u5373\u53ef\u3002<\/p>\n<p><span style=\"color:#0d0016\">Map \u5c01\u88c5\u7684\u5b9e\u73b0<\/span><\/p>\n<p>\u5bf9\u4e8e Map \u5c01\u88c5&#xff0c;\u5173\u952e\u662f\u8981\u6839\u636e\u7ea2\u9ed1\u6811\u7684\u5e95\u5c42\u5b9e\u73b0\u8981\u6c42\u63d0\u4f9b\u76f8\u5e94\u7684\u6a21\u677f\u53c2\u6570\u548c\u4eff\u51fd\u6570\u3002<\/p>\n<li>\n<p>\u6a21\u677f\u53c2\u6570\u4f20\u9012&#xff1a;<\/p>\n<p> Map \u9700\u8981\u6ee1\u8db3 K \u548c V \u7684\u6a21\u677f\u53c2\u6570\u4f20\u9012\u3002K \u8868\u793a\u952e\u7684\u7c7b\u578b&#xff0c;V \u8868\u793a\u503c\u7684\u7c7b\u578b\u3002<\/li>\n<li>\n<p>\u4eff\u51fd\u6570\u5b9e\u73b0&#xff1a;<\/p>\n<p> \u6211\u4eec\u9700\u8981\u5b9e\u73b0\u4e00\u4e2a\u4eff\u51fd\u6570&#xff0c;\u7528\u4e8e\u4ece\u5b58\u50a8\u7684 pair&lt;const K, V&gt; \u4e2d\u63d0\u53d6\u51fa Key\u3002\u56e0\u4e3a\u6bd4\u8f83\u903b\u8f91\u662f\u6bd4\u8f83\u952e\u503c&#xff0c;\u4f46\u662f\u5e95\u5c42\u7ea2\u9ed1\u6811\u5e76\u4e0d\u77e5\u9053T\u6a21\u677f\u53c2\u6570\u662fpair \u8fd8\u662fkey struct MapKeyOfT<br \/>\n{<br \/>\nconst K&amp; operator()(const pair&lt;K, V&gt;&amp; kv)<br \/>\n{<br \/>\nreturn kv.first;<br \/>\n}<br \/>\n}; <\/li>\n<li>\n<p>\u5e95\u5c42\u7ea2\u9ed1\u6811\u7684\u5b9e\u4f8b\u5316&#xff1a;<\/p>\n<p> \u5728 Map \u7c7b\u4e2d&#xff0c;\u6211\u4eec\u5b9e\u4f8b\u5316\u4e00\u4e2a\u5e95\u5c42\u7ea2\u9ed1\u6811&#xff0c;\u4f20\u5165\u5bf9\u5e94\u7684\u6a21\u677f\u53c2\u6570 K\u3001pair&lt;const K, V&gt;&#xff08;\u6ce8\u610f&#xff0c;\u952e\u662f\u4e0d\u53ef\u4fee\u6539\u7684&#xff0c;\u6240\u4ee5\u9700\u8981\u4f7f\u7528 pair&lt;const K, V&gt; \u6765\u786e\u4fdd\u952e\u662f\u5e38\u91cf&#xff09;&#xff0c;\u4ee5\u53ca MapOfT\u00a0\u4eff\u51fd\u6570\u3002\u8fd9\u6837&#xff0c;\u7ea2\u9ed1\u6811\u80fd\u591f\u9002\u5e94 Map \u4e2d\u952e\u503c\u5bf9\u7684\u5b58\u50a8\u65b9\u5f0f\u3002<\/li>\n<li>\n<p>\u8fed\u4ee3\u5668\u7684\u5b9e\u73b0&#xff1a;<\/p>\n<p> \u5728 Map \u7c7b\u4e2d&#xff0c;\u6211\u4eec\u8fd8\u9700\u8981\u5b9e\u73b0\u4e00\u4e2a\u8fed\u4ee3\u5668\u3002\u53ea\u9700\u8981\u63d0\u4f9b\u57fa\u672c\u7684 begin() \u548c end() \u63a5\u53e3&#xff0c;\u76f4\u63a5\u8c03\u7528\u5e95\u5c42\u7ea2\u9ed1\u6811\u7684\u76f8\u5173\u65b9\u6cd5\u5373\u53ef\u3002\u8fed\u4ee3\u5668\u7684\u524d\u8fdb&#xff08;&#043;&#043;&#xff09;\u548c\u540e\u9000&#xff08;&#8211;&#xff09;\u64cd\u4f5c\u4ea4\u7ed9\u5e95\u5c42\u7ea2\u9ed1\u6811\u7684\u8fed\u4ee3\u5668\u6765\u5904\u7406\u3002<\/li>\n<p>namespace xc<br \/>\n{<br \/>\ntemplate&lt;class K, class V&gt;<br \/>\nclass map<br \/>\n{<br \/>\nstruct MapKeyOfT<br \/>\n{<br \/>\nconst K&amp; operator()(const pair&lt;K, V&gt;&amp; kv)<br \/>\n{<br \/>\nreturn kv.first;<br \/>\n}<br \/>\n};<\/p>\n<p>public:<br \/>\ntypedef typename RBTree&lt;K, pair&lt;const K, V&gt;, MapKeyOfT&gt;::Iterator iterator;<br \/>\ntypedef typename RBTree&lt;K, pair&lt;const K, V&gt;, MapKeyOfT&gt;::ConstIterator const_iterator;<\/p>\n<p>iterator begin()<br \/>\n{<br \/>\nreturn _t.Begin();<br \/>\n}<\/p>\n<p>iterator end()<br \/>\n{<br \/>\nreturn _t.End();<br \/>\n}<br \/>\nconst_iterator begin()const<br \/>\n{<br \/>\nreturn _t.Begin();<br \/>\n}<\/p>\n<p>const_iterator end()const<br \/>\n{<br \/>\nreturn _t.End();<br \/>\n}<\/p>\n<p>pair&lt;iterator, bool&gt; insert(const pair&lt;K, V&gt;&amp; kv)<br \/>\n{<br \/>\nreturn _t.insert(kv);<br \/>\n}<\/p>\n<p>iterator find(const K&amp; key)<br \/>\n{<br \/>\nreturn _t.find(key);<br \/>\n}<\/p>\n<p>V&amp; operator[](const K&amp; key)<br \/>\n{<br \/>\npair&lt;iterator, bool&gt; ret &#061; insert({ key, V() });<br \/>\nreturn ret.first-&gt;second;<br \/>\n}<\/p>\n<p>private:<br \/>\nRBTree&lt;K, pair&lt;const K, V&gt;, MapKeyOfT&gt; _t;<br \/>\n};<br \/>\n} <\/p>\n<p><span style=\"color:#0d0016\">\u8fd9\u6837map \u5c01\u88c5\u597d\u4e86&#xff0c;\u6d4b\u8bd5\u4e00\u4e0b&#xff01;&#xff01;&#xff01;<\/span><\/p>\n<p>void test_map()<br \/>\n{<br \/>\nxc::map&lt;string, string&gt; dict;<br \/>\ndict.insert({ &#034;sort&#034;, &#034;\u6392\u5e8f&#034; });<br \/>\ndict.insert({ &#034;left&#034;, &#034;\u5de6\u8fb9&#034; });<br \/>\ndict.insert({ &#034;right&#034;, &#034;\u53f3\u8fb9&#034; });<br \/>\ndict[&#034;left&#034;] &#061; &#034;\u5de6\u8fb9&#xff0c;\u5269\u4f59&#034;;<br \/>\ndict[&#034;insert&#034;] &#061; &#034;\u63d2\u5165&#034;;<br \/>\ndict[&#034;string&#034;];<\/p>\n<p>xc::map&lt;string, string&gt;::iterator it &#061; dict.begin();<br \/>\nwhile (it !&#061; dict.end())<br \/>\n{<br \/>\n\/\/ \u4e0d\u80fd\u4fee\u6539first&#xff0c;\u53ef\u4ee5\u4fee\u6539second<br \/>\n\/\/it-&gt;first &#043;&#061; &#039;x&#039;;<br \/>\nit-&gt;second &#043;&#061; &#039;x&#039;;<br \/>\ncout &lt;&lt; it-&gt;first &lt;&lt; &#034;:&#034; &lt;&lt; it-&gt;second &lt;&lt; endl;<br \/>\n&#043;&#043;it;<br \/>\n}<br \/>\ncout &lt;&lt; endl;<\/p>\n<p>for (auto &amp;kv : dict)<br \/>\n{<br \/>\ncout &lt;&lt; kv.first &lt;&lt; &#034;:&#034; &lt;&lt; kv.second &lt;&lt; endl;<br \/>\n}<br \/>\ncout &lt;&lt; endl;<br \/>\n}<\/p>\n<p>int main()<br \/>\n{<br \/>\ntest_map();<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p><span style=\"color:#fe2c24\">\u53ef\u4ee5\u770b\u5230\u6211\u4eec\u5b9e\u73b0\u4e86 map \u7684\u5173\u952e\u91cd\u8f7d\u51fd\u6570 [ ]\u00a0<\/span><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"908\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250620220606-6855db4e26666.png\" width=\"1200\" \/><\/p>\n<p><span style=\"color:#0d0016\">map\u548cset\u4ece\u96f6\u5efa\u7acb\u8d77\u6765\u4e0d\u4ec5\u9700\u8981\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u77e5\u8bc6\u8fd8\u9700\u8981AVL\u6811\u548c\u7ea2\u9ed1\u6811\u7684\u4f7f\u7528&#xff01;&#xff01;&#xff01;\u751a\u81f3\u8fd8\u9700\u8981\u5bf9\u4e8e\u6a21\u7248\u7684\u66f4\u6df1\u7406\u89e3&#xff01;&#xff01;&#xff01;<\/span><\/p>\n<h2 id=\"Thanks%E8%B0%A2%E8%B0%A2%E9%98%85%E8%AF%BB%EF%BC%81%EF%BC%81%EF%BC%81\">Thanks\u8c22\u8c22\u9605\u8bfb&#xff01;&#xff01;&#xff01;<\/h2>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.9k\u6b21\uff0c\u70b9\u8d5e93\u6b21\uff0c\u6536\u85cf76\u6b21\u3002\u4eba\u751f\u7684\u6001\u5ea6\u662f\uff0c\u62b1\u6700\u5927\u7684\u5e0c\u671b\uff0c\u5c3d\u6700\u5927\u7684\u52aa\u529b\uff0c\u505a\u6700\u574f\u7684\u6253\u7b97\u3002\u2014\u2014 \u67cf\u62c9\u56fe \u300a\u7406\u60f3\u56fd\u300b\u76ee\u5f551\u3001\u7406\u8bba\u57fa\u77f3\u2014\u2014\u6df1\u5ea6\u5256\u6790 BSTree\u3001AVLTree \u4e0e RBTree \u7684\u6982\u5ff5\u533a\u522b2\u3001\u8fed\u4ee3\u5668\u673a\u5236\u2014\u2014RBTree \u8fed\u4ee3\u5668\u7684\u67b6\u6784\u4e0e\u5de5\u7a0b\u5b9e\u73b03\u3001\u9ad8\u7ea7\u5bb9\u5668\u8bbe\u8ba1\u2014\u2014Map \u4e0e Set \u7684\u6a21\u5757\u5316\u5c01\u88c53.1 \u6cdb\u578b\u652f\u6301\u589e\u5f3a\u2014\u2014RBTree \u6a21\u677f\u53c2\u6570\u8bbe\u8ba1\u4f18\u53163.2 Set \u5bb9\u5668\u6784\u5efa\u2014\u2014\u9762\u5411\u96c6\u5408\u64cd\u4f5c\u7684\u4f18\u5316\u8bbe\u8ba1 3.3 Map \u5bb9\u5668\u6784\u5efa\u2014\u2014\u9ad8\u6548\u952e\u503c\u5b58\u50a8\u7684\u5c01\u88c5\u5b9e\u73b0Thanks\u8c22\u8c22\u9605\u8bfb\uff01\uff01\uff01\u4e3a\u4e86\u5b9e\u73b0 Map \u548c Set \u7684\u5c01\u88c5\uff0c\u6211\u4eec\u9996\u5148\u8fdb\u884c\u4e86\u5145\u5206<\/p>\n","protected":false},"author":2,"featured_media":44886,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,99,190],"topic":[],"class_list":["post-44890","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-java","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010C++\u3011\u2014\u2014 \u4ece\u96f6\u5f00\u59cb\u5c01\u88c5 Map \u4e0e Set\uff1a\u5b9e\u73b0\u4e0e\u4f18\u5316 - \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\/44890.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010C++\u3011\u2014\u2014 \u4ece\u96f6\u5f00\u59cb\u5c01\u88c5 Map \u4e0e Set\uff1a\u5b9e\u73b0\u4e0e\u4f18\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.9k\u6b21\uff0c\u70b9\u8d5e93\u6b21\uff0c\u6536\u85cf76\u6b21\u3002\u4eba\u751f\u7684\u6001\u5ea6\u662f\uff0c\u62b1\u6700\u5927\u7684\u5e0c\u671b\uff0c\u5c3d\u6700\u5927\u7684\u52aa\u529b\uff0c\u505a\u6700\u574f\u7684\u6253\u7b97\u3002\u2014\u2014 \u67cf\u62c9\u56fe \u300a\u7406\u60f3\u56fd\u300b\u76ee\u5f551\u3001\u7406\u8bba\u57fa\u77f3\u2014\u2014\u6df1\u5ea6\u5256\u6790 BSTree\u3001AVLTree \u4e0e RBTree \u7684\u6982\u5ff5\u533a\u522b2\u3001\u8fed\u4ee3\u5668\u673a\u5236\u2014\u2014RBTree \u8fed\u4ee3\u5668\u7684\u67b6\u6784\u4e0e\u5de5\u7a0b\u5b9e\u73b03\u3001\u9ad8\u7ea7\u5bb9\u5668\u8bbe\u8ba1\u2014\u2014Map \u4e0e Set \u7684\u6a21\u5757\u5316\u5c01\u88c53.1 \u6cdb\u578b\u652f\u6301\u589e\u5f3a\u2014\u2014RBTree \u6a21\u677f\u53c2\u6570\u8bbe\u8ba1\u4f18\u53163.2 Set \u5bb9\u5668\u6784\u5efa\u2014\u2014\u9762\u5411\u96c6\u5408\u64cd\u4f5c\u7684\u4f18\u5316\u8bbe\u8ba1 3.3 Map \u5bb9\u5668\u6784\u5efa\u2014\u2014\u9ad8\u6548\u952e\u503c\u5b58\u50a8\u7684\u5c01\u88c5\u5b9e\u73b0Thanks\u8c22\u8c22\u9605\u8bfb\uff01\uff01\uff01\u4e3a\u4e86\u5b9e\u73b0 Map \u548c Set \u7684\u5c01\u88c5\uff0c\u6211\u4eec\u9996\u5148\u8fdb\u884c\u4e86\u5145\u5206\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/44890.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-20T22:06:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250620220604-6855db4c39a4f.gif\" \/>\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=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/44890.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/44890.html\",\"name\":\"\u3010C++\u3011\u2014\u2014 \u4ece\u96f6\u5f00\u59cb\u5c01\u88c5 Map \u4e0e Set\uff1a\u5b9e\u73b0\u4e0e\u4f18\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-06-20T22:06:07+00:00\",\"dateModified\":\"2025-06-20T22:06:07+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/44890.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/44890.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/44890.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010C++\u3011\u2014\u2014 \u4ece\u96f6\u5f00\u59cb\u5c01\u88c5 Map \u4e0e Set\uff1a\u5b9e\u73b0\u4e0e\u4f18\u5316\"}]},{\"@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":"\u3010C++\u3011\u2014\u2014 \u4ece\u96f6\u5f00\u59cb\u5c01\u88c5 Map \u4e0e Set\uff1a\u5b9e\u73b0\u4e0e\u4f18\u5316 - \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\/44890.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010C++\u3011\u2014\u2014 \u4ece\u96f6\u5f00\u59cb\u5c01\u88c5 Map \u4e0e Set\uff1a\u5b9e\u73b0\u4e0e\u4f18\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.9k\u6b21\uff0c\u70b9\u8d5e93\u6b21\uff0c\u6536\u85cf76\u6b21\u3002\u4eba\u751f\u7684\u6001\u5ea6\u662f\uff0c\u62b1\u6700\u5927\u7684\u5e0c\u671b\uff0c\u5c3d\u6700\u5927\u7684\u52aa\u529b\uff0c\u505a\u6700\u574f\u7684\u6253\u7b97\u3002\u2014\u2014 \u67cf\u62c9\u56fe \u300a\u7406\u60f3\u56fd\u300b\u76ee\u5f551\u3001\u7406\u8bba\u57fa\u77f3\u2014\u2014\u6df1\u5ea6\u5256\u6790 BSTree\u3001AVLTree \u4e0e RBTree \u7684\u6982\u5ff5\u533a\u522b2\u3001\u8fed\u4ee3\u5668\u673a\u5236\u2014\u2014RBTree \u8fed\u4ee3\u5668\u7684\u67b6\u6784\u4e0e\u5de5\u7a0b\u5b9e\u73b03\u3001\u9ad8\u7ea7\u5bb9\u5668\u8bbe\u8ba1\u2014\u2014Map \u4e0e Set \u7684\u6a21\u5757\u5316\u5c01\u88c53.1 \u6cdb\u578b\u652f\u6301\u589e\u5f3a\u2014\u2014RBTree \u6a21\u677f\u53c2\u6570\u8bbe\u8ba1\u4f18\u53163.2 Set \u5bb9\u5668\u6784\u5efa\u2014\u2014\u9762\u5411\u96c6\u5408\u64cd\u4f5c\u7684\u4f18\u5316\u8bbe\u8ba1 3.3 Map \u5bb9\u5668\u6784\u5efa\u2014\u2014\u9ad8\u6548\u952e\u503c\u5b58\u50a8\u7684\u5c01\u88c5\u5b9e\u73b0Thanks\u8c22\u8c22\u9605\u8bfb\uff01\uff01\uff01\u4e3a\u4e86\u5b9e\u73b0 Map \u548c Set \u7684\u5c01\u88c5\uff0c\u6211\u4eec\u9996\u5148\u8fdb\u884c\u4e86\u5145\u5206","og_url":"https:\/\/www.wsisp.com\/helps\/44890.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-06-20T22:06:07+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250620220604-6855db4c39a4f.gif"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/44890.html","url":"https:\/\/www.wsisp.com\/helps\/44890.html","name":"\u3010C++\u3011\u2014\u2014 \u4ece\u96f6\u5f00\u59cb\u5c01\u88c5 Map \u4e0e Set\uff1a\u5b9e\u73b0\u4e0e\u4f18\u5316 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-06-20T22:06:07+00:00","dateModified":"2025-06-20T22:06:07+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/44890.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/44890.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/44890.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010C++\u3011\u2014\u2014 \u4ece\u96f6\u5f00\u59cb\u5c01\u88c5 Map \u4e0e Set\uff1a\u5b9e\u73b0\u4e0e\u4f18\u5316"}]},{"@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\/44890","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=44890"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/44890\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/44886"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=44890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=44890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=44890"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=44890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}