{"id":91565,"date":"2026-08-07T23:41:25","date_gmt":"2026-08-07T15:41:25","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/91565.html"},"modified":"2026-08-07T23:41:25","modified_gmt":"2026-08-07T15:41:25","slug":"c-%e9%ab%98%e9%98%b6%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%ef%bc%9a%e4%ba%8c%e5%8f%89%e6%90%9c%e7%b4%a2%e6%a0%91%ef%bc%88bst%ef%bc%89%e4%b8%87%e5%ad%97%e8%af%a6%e8%a7%a3-%e5%8e%9f%e7%90%86%e3%80%81","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/91565.html","title":{"rendered":"C++ \u9ad8\u9636\u6570\u636e\u7ed3\u6784\uff1a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u4e07\u5b57\u8be6\u89e3 | \u539f\u7406\u3001\u589e\u5220\u67e5\u3001key \u4e0e key\u2011value \u53cc\u7248\u672c\u5b9e\u73b0\u3001\u770b\u61c2 set\/map \u5e95\u5c42"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E5%BC%95%E8%A8%80%EF%BC%9A-toc\" style=\"margin-left:0px\">\u5f15\u8a00&#xff1a;<\/p>\n<p id=\"1.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E6%A6%82%E5%BF%B5-toc\" style=\"margin-left:0px\">1.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6982\u5ff5<\/p>\n<p id=\"2.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E6%80%A7%E8%83%BD%E5%88%86%E6%9E%90-toc\" style=\"margin-left:0px\">2.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6027\u80fd\u5206\u6790<\/p>\n<p id=\"3.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E6%8F%92%E5%85%A5%E5%8E%9F%E7%90%86-toc\" style=\"margin-left:0px\">3.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u63d2\u5165\u539f\u7406<\/p>\n<p id=\"4.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E6%9F%A5%E6%89%BE%E5%8E%9F%E7%90%86-toc\" style=\"margin-left:0px\">4.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u67e5\u627e\u539f\u7406<\/p>\n<p id=\"5.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E5%88%A0%E9%99%A4%E5%8E%9F%E7%90%86-toc\" style=\"margin-left:0px\">5.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5220\u9664\u539f\u7406<\/p>\n<p id=\"6.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:0px\">6.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5b9e\u73b0<\/p>\n<p id=\"6.1.%E6%9E%84%E5%BB%BA%E5%88%9D%E6%9E%B6%E6%9E%84-toc\" style=\"margin-left:40px\">6.1.\u6784\u5efa\u521d\u67b6\u6784<\/p>\n<p id=\"%E6%8B%93%E5%B1%95%EF%BC%9Ausing%E5%85%B3%E9%94%AE%E5%AD%97-toc\" style=\"margin-left:80px\">\u62d3\u5c55&#xff1a;using\u5173\u952e\u5b57<\/p>\n<p id=\"6.2.%E6%8F%92%E5%85%A5%E5%AE%9E%E7%8E%B0%EF%BC%88Insert%EF%BC%89-toc\" style=\"margin-left:40px\">6.2.\u63d2\u5165\u5b9e\u73b0&#xff08;Insert&#xff09;<\/p>\n<p id=\"6.3.%E6%9E%90%E6%9E%84%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:40px\">6.3.\u6790\u6784\u5b9e\u73b0<\/p>\n<p id=\"6.4.Print%E5%AE%9E%E7%8E%B0%EF%BC%88%E6%B5%8B%E8%AF%95%EF%BC%89-toc\" style=\"margin-left:40px\">6.4.Print\u5b9e\u73b0&#xff08;\u6d4b\u8bd5&#xff09;<\/p>\n<p id=\"6.5.%E6%9F%A5%E6%89%BE%E5%AE%9E%E7%8E%B0%EF%BC%88find%EF%BC%89-toc\" style=\"margin-left:40px\">6.5.\u67e5\u627e\u5b9e\u73b0&#xff08;find&#xff09;<\/p>\n<p id=\"6.6.%E5%88%A0%E9%99%A4%E5%AE%9E%E7%8E%B0%EF%BC%88erase%EF%BC%89-toc\" style=\"margin-left:40px\">6.6.\u5220\u9664\u5b9e\u73b0&#xff08;erase&#xff09;<\/p>\n<p id=\"6.7.%E6%8B%B7%E8%B4%9D%E6%9E%84%E9%80%A0%EF%BC%8C%E8%B5%8B%E5%80%BC%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:40px\">6.7.\u62f7\u8d1d\u6784\u9020&#xff0c;\u8d4b\u503c\u5b9e\u73b0<\/p>\n<p id=\"6.8.%E6%BA%90%E7%A0%81-toc\" style=\"margin-left:40px\">6.8.\u6e90\u7801<\/p>\n<p id=\"7.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91key%E5%92%8Ckey%2Fvalue%E4%BD%BF%E7%94%A8%E5%9C%BA%E6%99%AF-toc\" style=\"margin-left:0px\">7.\u4e8c\u53c9\u641c\u7d22\u6811key\u548ckey\/value\u4f7f\u7528\u573a\u666f<\/p>\n<p id=\"7.1.key%E6%90%9C%E7%B4%A2%E5%9C%BA%E6%99%AF%EF%BC%88%E5%AF%B9%E5%BA%94set%E5%AE%B9%E5%99%A8%EF%BC%89-toc\" style=\"margin-left:40px\">7.1.key\u641c\u7d22\u573a\u666f&#xff08;\u5bf9\u5e94set\u5bb9\u5668&#xff09;<\/p>\n<p id=\"7.2.key%2Fvalue%E6%90%9C%E7%B4%A2%E5%9C%BA%E6%99%AF%EF%BC%88%E5%AF%B9%E5%BA%94map%E5%AE%B9%E5%99%A8%EF%BC%89-toc\" style=\"margin-left:40px\">7.2.key\/value\u641c\u7d22\u573a\u666f&#xff08;\u5bf9\u5e94map\u5bb9\u5668&#xff09;<\/p>\n<p id=\"7.3.key%2Fvalue%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:40px\">7.3.key\/value\u4e8c\u53c9\u641c\u7d22\u6811\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p id=\"%E7%BB%93%E8%AF%AD%EF%BC%9A-toc\" style=\"margin-left:0px\">\u7ed3\u8bed&#xff1a;<\/p>\n<hr id=\"hr-toc\" \/>\n<h2 id=\"%E5%BC%95%E8%A8%80%EF%BC%9A\" style=\"background-color:transparent\">\u5f15\u8a00&#xff1a;<\/h2>\n<p>\u4ece\u672c\u7bc7\u5f00\u59cb&#xff0c;\u6211\u4eec\u6b63\u5f0f\u8fdb\u5165\u9ad8\u9636\u6570\u636e\u7ed3\u6784\u7684\u5b66\u4e60\u9636\u6bb5\u3002 \u6807\u51c6\u8fdb\u9636\u5b66\u4e60\u8def\u7ebf\u63a8\u8350&#xff1a;\u666e\u901a\u4e8c\u53c9\u641c\u7d22\u6811 \u2192 \u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811 \u2192 AVL \u6811 \u2192 \u7ea2\u9ed1\u6811 \u2192 B \u6811 \/ B &#043; \u6811\u7cfb\u5217\u3002<\/p>\n<p>\u4e8c\u53c9\u641c\u7d22\u6811\u662f\u6240\u6709\u540e\u7eed\u5e73\u8861\u6811\u7684\u57fa\u77f3&#xff0c;\u4e5f\u662f C&#043;&#043; set\/map\u7684\u5e95\u5c42\u539f\u578b&#xff0c;\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<p>\u90a3\u4e48\u8bdd\u4e0d\u591a\u8bf4&#xff0c;\u76f4\u63a5\u8fdb\u5165\u6b63\u6587\u2014\u2014\u2014\u2014&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"315\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154121-6a75fca1dd66e.png\" width=\"315\" \/><\/p>\n<\/p>\n<hr \/>\n<h2 id=\"1.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E6%A6%82%E5%BF%B5\">1.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6982\u5ff5<\/h2>\n<p>\u4e8c\u53c9\u641c\u7d22\u6811\u53c8\u79f0\u4e8c\u53c9\u6392\u5e8f\u6811&#xff0c;\u5b83\u6216\u8005\u662f\u4e00\u68f5\u7a7a\u6811&#xff0c;\u6216\u8005\u662f\u5177\u6709\u4ee5\u4e0b\u6027\u8d28\u7684\u4e8c\u53c9\u6811:<\/p>\n<ul>\n<li>\u82e5\u5b83\u7684\u5de6\u5b50\u6811\u4e0d\u4e3a\u7a7a&#xff0c;\u5219\u5de6\u5b50\u6811\u4e0a\u6240\u6709\u7ed3\u70b9\u7684\u503c\u90fd\u5c0f\u4e8e\u7b49\u4e8e\u6839\u7ed3\u70b9\u7684\u503c<\/li>\n<li>\u82e5\u5b83\u7684\u53f3\u5b50\u6811\u4e0d\u4e3a\u7a7a&#xff0c;\u5219\u53f3\u5b50\u6811\u4e0a\u6240\u6709\u7ed3\u70b9\u7684\u503c\u90fd\u5927\u4e8e\u7b49\u4e8e\u6839\u7ed3\u70b9\u7684\u503c<\/li>\n<li>\u5b83\u7684\u5de6\u53f3\u5b50\u6811\u4e5f\u5206\u522b\u4e3a\u4e8c\u53c9\u641c\u7d22\u6811<\/li>\n<li>\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u53ef\u4ee5\u652f\u6301\u63d2\u5165\u76f8\u7b49\u7684\u503c&#xff0c;\u4e5f\u53ef\u4ee5\u4e0d\u652f\u6301\u63d2\u5165\u76f8\u7b49\u7684\u503c&#xff0c;\u5177\u4f53\u770b\u4f7f\u7528\u573a\u666f\u5b9a\u4e49&#xff0c;\u540e\u7eed\u6211\u4eec\u5b66\u4e60 map\/set\/multimap\/multiset \u7cfb\u5217\u5bb9\u5668\u5e95\u5c42\u5c31\u662f\u4e8c\u53c9\u641c\u7d22\u6811&#xff0c;\u5176\u4e2d map\/set \u4e0d\u652f\u6301\u63d2\u5165\u76f8\u7b49\u503c&#xff0c;multimap\/multiset \u652f\u6301\u63d2\u5165\u76f8\u7b49\u503c<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u5c31\u662f\u4e8c\u53c9\u641c\u7d22\u6811<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"258\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154122-6a75fca20d0f3.png\" width=\"326\" \/><\/p>\n<p><span style=\"color:#be191c\">\u7279\u522b\u6ce8\u610f&#xff1a;<\/span><span style=\"color:#1c7892\">\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d\u5e8f\u904d\u5386\u5f97\u5230\u5347\u5e8f\u5e8f\u5217\u3002<\/span><\/p>\n<p><span style=\"color:#be191c\">\u4e8c\u53c9\u6811\u5de6\u5b50\u6811\u4e2d\u6240\u6709\u8282\u70b9\u4e00\u5b9a\u4e0d\u5927\u4e8e\u6839\u8282\u70b9&#xff0c;\u53f3\u5b50\u6811\u4e2d\u6240\u6709\u8282\u70b9\u4e00\u5b9a\u4e0d\u5c0f\u4e8e\u6839\u8282\u70b9 &#xff0c;\u4e2d\u5e8f\u904d\u5386\u7684\u8bbf\u95ee\u987a\u5e8f\u662f\u5de6\u4e2d\u53f3&#xff0c;\u6240\u4ee5\u4ee5\u4e2d\u5e8f\u904d\u5386\u5f97\u5230\u7684\u5e8f\u5217\u5c31\u662f\u5347\u5e8f\u5e8f\u5217<\/span><\/p>\n<\/p>\n<hr \/>\n<h2 id=\"2.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E6%80%A7%E8%83%BD%E5%88%86%E6%9E%90\">2.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6027\u80fd\u5206\u6790<\/h2>\n<p>\u6700\u4f18\u60c5\u51b5\u4e0b&#xff0c;\u4e8c\u53c9\u641c\u7d22\u6811\u4e3a\u5b8c\u5168\u4e8c\u53c9\u6811 (\u6216\u8005\u63a5\u8fd1\u5b8c\u5168\u4e8c\u53c9\u6811)&#xff0c;\u5176\u9ad8\u5ea6\u4e3a&#xff1a;log N<\/p>\n<p>\u6700\u5dee\u60c5\u51b5\u4e0b&#xff0c;\u4e8c\u53c9\u641c\u7d22\u6811\u9000\u5316\u4e3a\u5355\u652f\u6811 (\u6216\u8005\u7c7b\u4f3c\u5355\u652f)&#xff0c;\u5176\u9ad8\u5ea6\u4e3a&#xff1a;N<\/p>\n<p>\u6240\u4ee5\u7efc\u5408\u800c\u8a00\u4e8c\u53c9\u641c\u7d22\u6811\u589e\u5220\u67e5\u6539\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a&#xff1a;O(N)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"286\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154122-6a75fca21d93b.png\" width=\"761\" \/><\/p>\n<p>\u90a3\u4e48\u8fd9\u6837\u7684\u6548\u7387\u663e\u7136\u662f\u65e0\u6cd5\u6ee1\u8db3\u6211\u4eec\u9700\u6c42\u7684&#xff0c;\u6211\u540e\u7eed\u4f1a\u7ee7\u7eed\u8bb2\u89e3\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u53d8\u5f62&#xff0c;\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811 AVL \u6811\u548c\u7ea2\u9ed1\u6811&#xff0c;\u624d\u80fd\u9002\u7528\u4e8e\u6211\u4eec\u5728\u5185\u5b58\u4e2d\u5b58\u50a8\u548c\u641c\u7d22\u6570\u636e\u3002\u4e8c\u53c9\u641c\u7d22\u6811\u4e3b\u8981\u662f\u4e3a\u4e86\u6253\u597d\u94fa\u57ab<\/p>\n<p>\u53e6\u5916\u9700\u8981\u8bf4\u660e\u7684\u662f&#xff0c;\u4e8c\u5206\u67e5\u627e\u4e5f\u53ef\u4ee5\u5b9e\u73b0O(log\u00a0N)\u7ea7\u522b\u7684\u67e5\u627e\u6548\u7387&#xff0c;\u4f46\u662f\u4e8c\u5206\u67e5\u627e\u6709\u4e24\u5927\u7f3a\u9677&#xff1a;<\/p>\n<li>\u9700\u8981\u5b58\u50a8\u5728\u652f\u6301\u4e0b\u6807\u968f\u673a\u8bbf\u95ee\u7684\u7ed3\u6784\u4e2d&#xff0c;\u5e76\u4e14\u6709\u5e8f\u3002<\/li>\n<li>\u63d2\u5165\u548c\u5220\u9664\u6570\u636e\u6548\u7387\u5f88\u4f4e&#xff0c;\u56e0\u4e3a\u5b58\u50a8\u5728\u4e0b\u6807\u968f\u673a\u8bbf\u95ee\u7684\u7ed3\u6784\u4e2d&#xff0c;\u63d2\u5165\u548c\u5220\u9664\u6570\u636e\u4e00\u822c\u9700\u8981\u632a\u52a8\u6570\u636e\u3002<\/li>\n<p>\u8fd9\u91cc\u4e5f\u5c31\u4f53\u73b0\u51fa\u4e86\u5e73\u8861\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u4ef7\u503c\u3002<\/p>\n<\/p>\n<hr \/>\n<h2 id=\"3.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E6%8F%92%E5%85%A5%E5%8E%9F%E7%90%86\">3.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u63d2\u5165\u539f\u7406<\/h2>\n<p>\u6211\u8fd9\u91cc\u5148\u8bb2\u7406\u8bba&#xff0c;\u540e\u5b9e\u73b0<\/p>\n<p>\u63d2\u5165\u7684\u5177\u4f53\u8fc7\u7a0b\u5982\u4e0b&#xff1a;<\/p>\n<li>\u6811\u4e3a\u7a7a&#xff0c;\u5219\u76f4\u63a5\u65b0\u589e\u7ed3\u70b9&#xff0c;\u8d4b\u503c\u7ed9 root \u6307\u9488<\/li>\n<li>\u6811\u4e0d\u7a7a&#xff0c;\u6309\u4e8c\u53c9\u641c\u7d22\u6811\u6027\u8d28&#xff0c;\u63d2\u5165\u503c\u6bd4\u5f53\u524d\u7ed3\u70b9\u5927\u5f80\u53f3\u8d70&#xff0c;\u63d2\u5165\u503c\u6bd4\u5f53\u524d\u7ed3\u70b9\u5c0f\u5f80\u5de6\u8d70&#xff0c;\u627e\u5230\u7a7a\u4f4d\u7f6e&#xff0c;\u63d2\u5165\u65b0\u7ed3\u70b9\u3002<\/li>\n<li>\u5982\u679c\u652f\u6301\u63d2\u5165\u76f8\u7b49\u7684\u503c&#xff0c;\u63d2\u5165\u503c\u8ddf\u5f53\u524d\u7ed3\u70b9\u76f8\u7b49\u7684\u503c\u53ef\u4ee5\u5f80\u53f3\u8d70&#xff0c;\u4e5f\u53ef\u4ee5\u5f80\u5de6\u8d70&#xff0c;\u627e\u5230\u7a7a\u4f4d\u7f6e&#xff0c;\u63d2\u5165\u65b0\u7ed3\u70b9\u3002&#xff08;\u8981\u6ce8\u610f\u7684\u662f\u8981\u4fdd\u6301\u903b\u8f91\u4e00\u81f4\u6027&#xff0c;\u63d2\u5165\u76f8\u7b49\u7684\u503c\u4e0d\u8981\u4e00\u4f1a\u5f80\u53f3\u8d70&#xff0c;\u4e00\u4f1a\u5f80\u5de6\u8d70&#xff09;<\/li>\n<p>\u5c31\u6bd4\u5982&#xff0c;\u4e00\u4e2a\u4e8c\u53c9\u641c\u7d22\u6811\u5df2\u7ecf\u6784\u5efa\u6210\u4e86\u8fd9\u6837<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"313\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154122-6a75fca22e53c.png\" width=\"445\" \/><\/p>\n<p>\u6211\u60f3\u63d2\u516516\u5c31\u8d70\u8fd9\u6761\u7ea2\u7ebf\u8def<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"313\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154122-6a75fca23f3c7.png\" width=\"454\" \/><\/p>\n<p>\u6211\u60f3\u63d2\u51653\u5c31\u8d70\u8fd9\u6761\u7ea2\u7ebf\u8def&#xff08;\u8fd9\u91cc\u76f8\u540c\u60c5\u51b5\u4e0b\u662f\u5f80\u53f3\u8d70&#xff0c;\u5f80\u5de6\u8d70\u5f53\u7136\u4e5f\u53ef\u4ee5&#xff0c;\u53ea\u8981\u903b\u8f91\u4e00\u81f4\u5c31\u53ef\u4ee5&#xff09;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"390\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154122-6a75fca25015b.png\" width=\"566\" \/><\/p>\n<\/p>\n<hr \/>\n<h2 id=\"4.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E6%9F%A5%E6%89%BE%E5%8E%9F%E7%90%86\">4.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u67e5\u627e\u539f\u7406<\/h2>\n<ul>\n<li>\u4ece\u6839\u5f00\u59cb\u6bd4\u8f83&#xff0c;\u67e5\u627e x&#xff0c;x \u6bd4\u6839\u7684\u503c\u5927\u5219\u5f80\u53f3\u8fb9\u8d70\u67e5\u627e&#xff0c;x \u6bd4\u6839\u503c\u5c0f\u5219\u5f80\u5de6\u8fb9\u8d70\u67e5\u627e\u3002<\/li>\n<li>\u6700\u591a\u67e5\u627e\u9ad8\u5ea6\u6b21&#xff0c;\u8d70\u5230\u5230\u7a7a&#xff0c;\u8fd8\u6ca1\u627e\u5230&#xff0c;\u8fd9\u4e2a\u503c\u4e0d\u5b58\u5728\u3002<\/li>\n<li>\u5982\u679c\u4e0d\u652f\u6301\u63d2\u5165\u76f8\u7b49\u7684\u503c&#xff0c;\u627e\u5230 x \u5373\u53ef\u8fd4\u56de<\/li>\n<li><span style=\"color:#1c7892\">\u5982\u679c\u652f\u6301\u63d2\u5165\u76f8\u7b49\u7684\u503c&#xff0c;\u610f\u5473\u7740\u6709\u591a\u4e2a x \u5b58\u5728&#xff0c;<\/span><span style=\"color:#be191c\">\u4e00\u822c\u8981\u6c42\u67e5\u627e\u4e2d\u5e8f\u7684\u7b2c\u4e00\u4e2a x<\/span><span style=\"color:#1c7892\">\u3002\u5982\u4e0b\u56fe&#xff0c;\u67e5\u627e 3&#xff0c;\u8981\u627e\u5230 1 \u7684\u53f3\u5b69\u5b50\u7684\u90a3\u4e2a 3 \u8fd4\u56de&#xff08;\u56e0\u4e3a\u662f\u67e5\u627e\u4e2d\u5e8f\u7684\u7b2c\u4e00\u4e2ax&#xff0c;\u6240\u4ee5\u6211\u4eec\u9047\u5230\u627e\u5230x\u540e\u8981\u5f80\u5de6\u5b50\u6811\u63a5\u7740\u627e&#xff09;<\/span><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"324\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154122-6a75fca262b97.png\" width=\"466\" \/><\/p>\n<\/p>\n<hr \/>\n<h2 id=\"5.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E5%88%A0%E9%99%A4%E5%8E%9F%E7%90%86\">5.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5220\u9664\u539f\u7406<\/h2>\n<p>\u9996\u5148\u67e5\u627e\u5143\u7d20\u662f\u5426\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d&#xff0c;\u5982\u679c\u4e0d\u5b58\u5728&#xff0c;\u5219\u8fd4\u56de false\u3002 \u5982\u679c\u67e5\u627e\u5143\u7d20\u5b58\u5728\u5219\u5206\u4ee5\u4e0b\u56db\u79cd\u60c5\u51b5\u5206\u522b\u5904\u7406&#xff1a;&#xff08;\u5047\u8bbe\u8981\u5220\u9664\u7684\u7ed3\u70b9\u4e3a N&#xff09;<\/p>\n<li>\u8981\u5220\u9664\u7ed3\u70b9 N \u5de6\u53f3\u5b69\u5b50\u5747\u4e3a\u7a7a<\/li>\n<li>\u8981\u5220\u9664\u7684\u7ed3\u70b9 N \u5de6\u5b69\u5b50\u4e3a\u7a7a&#xff0c;\u53f3\u5b69\u5b50\u7ed3\u70b9\u4e0d\u4e3a\u7a7a<\/li>\n<li>\u8981\u5220\u9664\u7684\u7ed3\u70b9 N \u53f3\u5b69\u5b50\u4e3a\u7a7a&#xff0c;\u5de6\u5b69\u5b50\u7ed3\u70b9\u4e0d\u4e3a\u7a7a<\/li>\n<li>\u8981\u5220\u9664\u7684\u7ed3\u70b9 N \u5de6\u53f3\u5b69\u5b50\u7ed3\u70b9\u5747\u4e0d\u4e3a\u7a7a<\/li>\n<p>\u5bf9\u5e94\u4ee5\u4e0a\u56db\u79cd\u60c5\u51b5\u7684\u89e3\u51b3\u65b9\u6848&#xff1a;<\/p>\n<li>\u628a N \u7ed3\u70b9\u7684\u7236\u4eb2\u5bf9\u5e94\u5b69\u5b50\u6307\u9488\u6307\u5411\u7a7a&#xff0c;\u76f4\u63a5\u5220\u9664 N \u7ed3\u70b9&#xff08;\u60c5\u51b5 1 \u53ef\u4ee5\u5f53\u6210 2 \u6216\u8005 3 \u5904\u7406&#xff0c;\u6548\u679c\u662f\u4e00\u6837\u7684&#xff09;<\/li>\n<li>\u628a N \u7ed3\u70b9\u7684\u7236\u4eb2\u5bf9\u5e94\u5b69\u5b50\u6307\u9488\u6307\u5411 N \u7684\u53f3\u5b69\u5b50&#xff0c;\u76f4\u63a5\u5220\u9664 N \u7ed3\u70b9<\/li>\n<li>\u628a N \u7ed3\u70b9\u7684\u7236\u4eb2\u5bf9\u5e94\u5b69\u5b50\u6307\u9488\u6307\u5411 N \u7684\u5de6\u5b69\u5b50&#xff0c;\u76f4\u63a5\u5220\u9664 N \u7ed3\u70b9<\/li>\n<li>\u65e0\u6cd5\u76f4\u63a5\u5220\u9664 N \u7ed3\u70b9&#xff0c;\u56e0\u4e3a N \u7684\u4e24\u4e2a\u5b69\u5b50\u65e0\u5904\u5b89\u653e&#xff0c;\u53ea\u80fd\u7528\u66ff\u6362\u6cd5\u5220\u9664\u3002\u627e N \u5de6\u5b50\u6811\u7684\u503c\u6700\u5927\u7ed3\u70b9 R (\u6700\u53f3\u7ed3\u70b9) \u6216\u8005 N \u53f3\u5b50\u6811\u7684\u503c\u6700\u5c0f\u7ed3\u70b9 R (\u6700\u5de6\u7ed3\u70b9) \u66ff\u4ee3 N&#xff0c;\u56e0\u4e3a\u8fd9\u4e24\u4e2a\u7ed3\u70b9\u4e2d\u4efb\u610f\u4e00\u4e2a&#xff0c;\u653e\u5230 N \u7684\u4f4d\u7f6e&#xff0c;\u90fd\u6ee1\u8db3\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u89c4\u5219\u3002\u66ff\u4ee3 N \u7684\u610f\u601d\u5c31\u662f N \u548c R \u7684\u4e24\u4e2a\u7ed3\u70b9\u7684\u503c\u4ea4\u6362&#xff0c;\u8f6c\u800c\u53d8\u6210\u5220\u9664 R \u7ed3\u70b9&#xff0c;R \u7ed3\u70b9\u7b26\u5408\u60c5\u51b5 2 \u6216\u60c5\u51b5 3&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u5220\u9664\u3002<\/li>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"308\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154122-6a75fca274347.png\" width=\"463\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"310\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154122-6a75fca285395.png\" width=\"466\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"311\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154122-6a75fca295ff0.png\" width=\"463\" \/><\/p>\n<\/p>\n<hr \/>\n<h2 id=\"6.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E7%9A%84%E5%AE%9E%E7%8E%B0\">6.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5b9e\u73b0<\/h2>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u6211\u4eec\u8bbe\u8ba1\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u65f6\u5019\u4f1a\u6709\u4fe9\u4efd\u7248\u672c&#xff0c;\u4e00\u4efd\u662f\u652f\u6301\u5197\u4f59\u7684&#xff08;\u6709\u91cd\u590d\u6570\u5b57&#xff09;&#xff0c;\u4e00\u4efd\u662f\u4e0d\u652f\u6301\u5197\u4f59\u7684&#xff08;\u6ca1\u6709\u91cd\u590d\u6570\u5b57&#xff09;&#xff0c;\u8fd9\u5176\u5b9e\u5c31\u662fset\u548cmap\u5e95\u5c42\u7684\u533a\u522b&#xff0c;\u6211\u4eec\u8fd9\u91cc\u5b9e\u73b0\u4e0d\u652f\u6301\u5197\u4f59\u7684\u7248\u672c<\/p>\n<p>\u6211\u4eec\u8fd9\u91cc\u5b9e\u73b0\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u5b9e\u73b0\u4e86\u589e\u5220\u67e5\u7684\u529f\u80fd&#xff0c;\u6539\u4e0d\u5b9e\u73b0&#xff0c;\u56e0\u4e3a\u666e\u901a\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u662f\u4e0d\u5141\u8bb8\u4fee\u6539\u7684&#xff08;\u56e0\u4e3a\u5982\u679c\u6539\u4e86&#xff0c;\u90a3\u6811\u5c31\u53ef\u80fd\u4e0d\u662f\u4e8c\u53c9\u641c\u7d22\u6811\u4e86&#xff0c;\u6027\u8d28\u5c31\u88ab\u7834\u574f\u4e86&#xff09;<\/p>\n<h3 id=\"6.1.%E6%9E%84%E5%BB%BA%E5%88%9D%E6%9E%B6%E6%9E%84\">6.1.\u6784\u5efa\u521d\u67b6\u6784<\/h3>\n<p>#pragma once<br \/>\n#include &lt;iostream&gt;<br \/>\ntemplate&lt;class K&gt;<br \/>\nclass BSTNode<br \/>\n{<br \/>\npublic:<br \/>\nBSTNode() &#061; default;<br \/>\nBSTNode(const K&amp; _key)<br \/>\n:_val(_key)<br \/>\n, _left(nullptr)<br \/>\n, _right(nullptr)<br \/>\n{<\/p>\n<p>}<\/p>\n<p>K _val &#061; 0;<br \/>\nBSTNode&lt;K&gt;* _left &#061; nullptr;<br \/>\nBSTNode&lt;K&gt;* _right &#061; nullptr;<br \/>\n};<\/p>\n<p>template&lt;class K&gt;<br \/>\nclass BSTree<br \/>\n{<br \/>\nusing Node &#061; BSTNode&lt;K&gt;;<br \/>\n\/\/typedef BSTNode&lt;K&gt; Node;<br \/>\npublic:<\/p>\n<p>private:<br \/>\nNode* _root &#061; nullptr;<br \/>\n}; <\/p>\n<p>BSTNode\u5c31\u662f\u4ee3\u8868\u8282\u70b9&#xff0c;BSTree\u5c31\u662f\u6811<\/p>\n<h4 id=\"%E6%8B%93%E5%B1%95%EF%BC%9Ausing%E5%85%B3%E9%94%AE%E5%AD%97\">\u62d3\u5c55&#xff1a;using\u5173\u952e\u5b57<\/h4>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u6211\u4eec\u5148\u524d\u7528\u91cd\u547d\u540d\u7528\u7684\u662ftypedef&#xff0c;\u4e5f\u5c31\u662f<\/p>\n<p>typedef BSTNode&lt;K&gt; Node;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u8fd9\u91cc\u62d3\u5c55\u4e00\u70b9&#xff0c;\u6211\u4eec\u53ef\u4ee5\u7528using\u5173\u952e\u5b57\u6765\u8fdb\u884c\u91cd\u547d\u540d&#xff0c;\u8fd9\u6548\u679c\u662fC&#043;&#043;11\u540e\u65b0\u589e\u7684\u4e1c\u897f&#xff0c;\u73b0\u5728\u53ef\u4ee5\u4ecetypedef\u8f6c\u5230\u7528using&#xff0c;\u56e0\u4e3ausing\u5728\u666e\u901a\u573a\u666f\u4e0b\u6548\u679c\u548ctypedef\u662f\u4e00\u6837\u7684&#xff0c;\u4f46\u5728\u6709\u4e9b\u573a\u666f\u633a\u6709\u7528&#xff0c;\u5177\u4f53\u4f1a\u5728C&#043;&#043;11\u90e8\u5206\u5177\u4f53\u8bb2using&#xff0c;\u8fd9\u4e2a\u7528\u6cd5\u4e5f\u5f88\u7b80\u5355&#xff0c;\u5c31\u662f\u5982\u4e0b\u8fd9\u6837<\/p>\n<p>using Node &#061; BSTNode&lt;K&gt;; <\/p>\n<h3 id=\"6.2.%E6%8F%92%E5%85%A5%E5%AE%9E%E7%8E%B0%EF%BC%88Insert%EF%BC%89\">6.2.\u63d2\u5165\u5b9e\u73b0&#xff08;Insert&#xff09;<\/h3>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u8fd9\u91cc\u5b9e\u73b0\u7684\u662f\u65e0\u91cd\u590d\u6570\u636e\u7248\u672c<\/p>\n<p>template&lt;class K&gt;<br \/>\nbool BSTree&lt;K&gt;::insert(const K&amp; key)<br \/>\n{<br \/>\nif (_root &#061;&#061; nullptr)<br \/>\n{<br \/>\nNode* node &#061; new Node(key);<br \/>\n_root &#061; node;<br \/>\nreturn true;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nNode* cur &#061; _root;<br \/>\nNode* parent &#061; nullptr;<br \/>\nwhile (cur)<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\nif (cur-&gt;_val &gt; key)<br \/>\ncur &#061; cur-&gt;_left;<br \/>\nelse if (cur-&gt;_val &lt; key)<br \/>\ncur &#061; cur-&gt;_right;<br \/>\nelse<br \/>\nreturn false;<br \/>\n}<br \/>\nNode* node &#061; new Node(key);<br \/>\nif (parent-&gt;_val &gt; key)<br \/>\nparent-&gt;_left &#061; node;<br \/>\nelse<br \/>\nparent-&gt;_right &#061; node;<br \/>\nreturn true;<br \/>\n}<br \/>\n}<\/p>\n<h3 id=\"6.3.%E6%9E%90%E6%9E%84%E5%AE%9E%E7%8E%B0\" style=\"background-color:transparent\">6.3.\u6790\u6784\u5b9e\u73b0<\/h3>\n<p>insert\u51fd\u6570\u6d89\u53ca\u4e86\u5806\u5185\u5b58\u7684\u5f00\u8f9f&#xff0c;\u90a3\u6211\u4eec\u5c31\u5b9e\u73b0\u4e00\u4e0b\u6790\u6784<\/p>\n<p>\/\/\u7c7b\u5185<br \/>\n    \/\/&#8230;..<br \/>\n~BSTree()<br \/>\n{<br \/>\nDestroy(_root);<br \/>\n}<br \/>\nvoid Destroy(Node* root);<br \/>\n    \/\/&#8230;<\/p>\n<p>\/\/\u7c7b\u5916<br \/>\ntemplate&lt;class K&gt;<br \/>\nvoid BSTree&lt;K&gt;::Destroy(Node* root)<br \/>\n{<br \/>\nif (root &#061;&#061; nullptr)<br \/>\nreturn;<br \/>\nDestroy(root-&gt;_left);<br \/>\nDestroy(root-&gt;_right);<br \/>\ndelete root;<br \/>\n} <\/p>\n<h3 id=\"6.4.Print%E5%AE%9E%E7%8E%B0%EF%BC%88%E6%B5%8B%E8%AF%95%EF%BC%89\">6.4.Print\u5b9e\u73b0&#xff08;\u6d4b\u8bd5&#xff09;<\/h3>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u8fd9\u91cc\u5b9e\u73b0Print\u51fd\u6570\u662f\u4e3a\u4e86\u6d4b\u8bd5\u5b9e\u73b0\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u6709\u6ca1\u6709\u95ee\u9898&#xff0c;\u4e3a\u4e86\u4e0d\u8ba9\u5916\u90e8\u76f4\u63a5\u8c03\u7528\u5e26\u53c2\u7684Print&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5c01\u88c5\u4e00\u5c42,\u7136\u540e\u628a\u5e26\u53c2\u7684Print\u8bbe\u4e3a\u79c1\u6709<\/p>\n<p>template&lt;class K&gt;<br \/>\nvoid BSTree&lt;K&gt;::Print()<br \/>\n{<br \/>\nPrint(_root);<br \/>\n}<\/p>\n<p>template&lt;class K&gt;<br \/>\nvoid BSTree&lt;K&gt;::Print(Node* root)<br \/>\n{<br \/>\nif (root &#061;&#061; nullptr)<br \/>\nreturn;<br \/>\nPrint(root-&gt;_left);<br \/>\nstd::cout &lt;&lt; root-&gt;_val &lt;&lt; &#034; &#034;;<br \/>\nPrint(root-&gt;_right);<br \/>\n} <\/p>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u6211\u4eec\u6d4b\u8bd5\u4e00\u4e0binsert\u6709\u6ca1\u6709\u95ee\u9898<\/p>\n<p>#define _CRT_SECURE_NO_WARNINGS<br \/>\n#include &#034;Binary Search Tree.h&#034;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<br \/>\nint main()<br \/>\n{<br \/>\nBSTree&lt;int&gt; bsti;<br \/>\nbsti.insert(1);<br \/>\nbsti.insert(3);<br \/>\nbsti.insert(2);<br \/>\nbsti.insert(4);<br \/>\nbsti.insert(4);<br \/>\nbsti.Print();<\/p>\n<p>cout &lt;&lt; endl;<\/p>\n<p>BSTree&lt;string&gt; bsts;<br \/>\nbsts.insert(&#034;ababab&#034;);<br \/>\nbsts.insert(&#034;baabab&#034;);<br \/>\nbsts.insert(&#034;aabbab&#034;);<br \/>\nbsts.insert(&#034;bbabab&#034;);<br \/>\nbsts.insert(&#034;bbabab&#034;);<br \/>\nbsts.Print();<\/p>\n<p>return 0;<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"207\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154122-6a75fca2a6ffd.png\" width=\"1176\" \/><\/p>\n<p>\u5bf9\u4e8e\u5185\u7f6e\u7c7b\u578b\u548c\u81ea\u5b9a\u4e49\u7c7b\u578b\u90fd\u662f\u6ca1\u95ee\u9898\u7684<\/p>\n<\/p>\n<h3 id=\"6.5.%E6%9F%A5%E6%89%BE%E5%AE%9E%E7%8E%B0%EF%BC%88find%EF%BC%89\">6.5.\u67e5\u627e\u5b9e\u73b0&#xff08;find&#xff09;<\/h3>\n<p>template&lt;class K&gt;<br \/>\nbool BSTree&lt;K&gt;::find(const K&amp; key)<br \/>\n{<br \/>\nNode* cur &#061; _root;<br \/>\nwhile (cur)<br \/>\n{<br \/>\nif (cur-&gt;_val &gt; key)<br \/>\ncur &#061; cur-&gt;_left;<br \/>\nelse if (cur-&gt;_val &lt; key)<br \/>\ncur &#061; cur-&gt;_right;<br \/>\nelse<br \/>\nreturn true;<br \/>\n}<br \/>\nreturn false;<br \/>\n} <\/p>\n<p>\u6d4b\u8bd5\u4e00\u4e0b<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"790\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154122-6a75fca2c7e53.png\" width=\"1666\" \/><\/p>\n<\/p>\n<h3 id=\"6.6.%E5%88%A0%E9%99%A4%E5%AE%9E%E7%8E%B0%EF%BC%88erase%EF%BC%89\" style=\"background-color:transparent\">6.6.\u5220\u9664\u5b9e\u73b0&#xff08;erase&#xff09;<\/h3>\n<p>template&lt;class K&gt;<br \/>\nbool BSTree&lt;K&gt;::erase(const K&amp; key)<br \/>\n{<br \/>\nif (_root &#061;&#061; nullptr)<br \/>\nreturn false;<br \/>\nNode* cur &#061; _root;<br \/>\nNode* parent &#061; nullptr;<br \/>\nwhile (cur)<br \/>\n{<br \/>\nif (cur-&gt;_val &gt; key)<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\ncur &#061; cur-&gt;_left;<br \/>\n}<br \/>\nelse if (cur-&gt;_val &lt; key)<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\ncur &#061; cur-&gt;_right;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (cur-&gt;_left &#061;&#061; nullptr)<br \/>\n{<br \/>\nif (cur &#061;&#061; _root)<br \/>\n{<br \/>\n_root &#061; cur-&gt;_right;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (parent-&gt;_right &#061;&#061; cur)<br \/>\nparent-&gt;_right &#061; cur-&gt;_right;<br \/>\nelse<br \/>\nparent-&gt;_left &#061; cur-&gt;_right;<br \/>\n}<br \/>\ndelete cur;<br \/>\n}<br \/>\nelse if (cur-&gt;_right &#061;&#061; nullptr)<br \/>\n{<br \/>\nif (cur &#061;&#061; _root)<br \/>\n{<br \/>\n_root &#061; cur-&gt;_left;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (parent-&gt;_right &#061;&#061; cur)<br \/>\nparent-&gt;_right &#061; cur-&gt;_left;<br \/>\nelse<br \/>\nparent-&gt;_left &#061; cur-&gt;_left;<br \/>\n}<br \/>\ndelete cur;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nNode* sparent &#061; cur;<br \/>\nNode* scur &#061; cur-&gt;_right;<br \/>\nwhile (scur-&gt;_left)<br \/>\n{<br \/>\nsparent &#061; scur;<br \/>\nscur &#061; scur-&gt;_left;<br \/>\n}<br \/>\ncur-&gt;_val &#061; scur-&gt;_val;<br \/>\nif (sparent &#061;&#061; cur)<br \/>\nsparent-&gt;_right &#061; scur-&gt;_right;<br \/>\nelse<br \/>\nsparent-&gt;_left &#061; scur-&gt;_right;<br \/>\ndelete scur;<br \/>\nbreak;<br \/>\n}<br \/>\nreturn true;<br \/>\n}<br \/>\n}<br \/>\nreturn false;<br \/>\n} <\/p>\n<p>\u6211\u7528\u8fd9\u4efd\u6d4b\u8bd5\u4ee3\u7801\u6d4b\u8bd5\u4e00\u4e0b<\/p>\n<p>#define _CRT_SECURE_NO_WARNINGS<br \/>\n#include &#034;Binary Search Tree.h&#034;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<br \/>\nint main()<br \/>\n{<br \/>\nint a[] &#061; { 8,3,1,10,6,4,7,14,13 };<br \/>\nBSTree&lt;int&gt; bsti;<br \/>\nfor (auto x : a)<br \/>\nbsti.insert(x);<br \/>\nbsti.Print();<br \/>\ncout &lt;&lt; endl;<\/p>\n<p>bsti.erase(3);<br \/>\nbsti.Print();<br \/>\ncout &lt;&lt; endl;<\/p>\n<p>bsti.erase(14);<br \/>\nbsti.Print();<br \/>\ncout &lt;&lt; endl;<\/p>\n<p>bsti.erase(8);<br \/>\nbsti.Print();<br \/>\ncout &lt;&lt; endl;<\/p>\n<p>\/\/BSTree&lt;string&gt; bsts;<br \/>\n\/\/bsts.insert(&#034;ababab&#034;);<br \/>\n\/\/bsts.insert(&#034;baabab&#034;);<br \/>\n\/\/bsts.insert(&#034;aabbab&#034;);<br \/>\n\/\/bsts.insert(&#034;bbabab&#034;);<br \/>\n\/\/bsts.insert(&#034;bbabab&#034;);<br \/>\n\/\/bsts.Print();<br \/>\n\/\/cout &lt;&lt; bsts.find(&#034;aabbab&#034;) &lt;&lt; &#034; &#034; &lt;&lt; bsts.find(&#034;aabbbb&#034;);<\/p>\n<p>return 0;<br \/>\n} <\/p>\n<p>\u6ca1\u6709\u95ee\u9898\u00a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"719\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154123-6a75fca3ae9ad.png\" width=\"1412\" \/><\/p>\n<\/p>\n<h3 id=\"6.7.%E6%8B%B7%E8%B4%9D%E6%9E%84%E9%80%A0%EF%BC%8C%E8%B5%8B%E5%80%BC%E5%AE%9E%E7%8E%B0\">6.7.\u62f7\u8d1d\u6784\u9020&#xff0c;\u8d4b\u503c\u5b9e\u73b0<\/h3>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u4e3a\u4e86\u9884\u9632\u6d45\u62f7\u8d1d&#xff0c;\u6700\u540e\u628a\u62f7\u8d1d\u6784\u9020\u548c\u8d4b\u503c\u5b9e\u73b0\u4e00\u4e0b\u5c31OK\u4e86<\/p>\n<p>\/\/\u7c7b\u5185<br \/>\nBSTree&lt;K&gt;&amp; operator&#061;(BSTree&lt;K&gt; bst);<\/p>\n<p>BSTree() &#061; default;<\/p>\n<p>BSTree(const BSTree&amp; bst)<br \/>\n{<br \/>\n_root &#061; Creat(bst._root);<br \/>\n}<br \/>\nNode* Creat(Node* root);<\/p>\n<p>\/\/\u7c7b\u5916<br \/>\ntemplate&lt;class K&gt;<br \/>\ntypename BSTree&lt;K&gt;::Node* BSTree&lt;K&gt;::Creat(Node* root)<br \/>\n{<br \/>\nif (root &#061;&#061; nullptr)<br \/>\nreturn nullptr;<br \/>\nNode* cur &#061; new Node(root-&gt;_val);<br \/>\ncur-&gt;_left &#061; Creat(root-&gt;_left);<br \/>\ncur-&gt;_right &#061; Creat(root-&gt;_right);<br \/>\nreturn cur;<br \/>\n}<\/p>\n<p>template&lt;class K&gt;<br \/>\nBSTree&lt;K&gt;&amp; BSTree&lt;K&gt;::operator&#061;(BSTree&lt;K&gt; bst)<br \/>\n{<br \/>\nstd::swap(_root, bst._root);<br \/>\nreturn *this;<br \/>\n}<\/p>\n<h3 id=\"6.8.%E6%BA%90%E7%A0%81\">6.8.\u6e90\u7801<\/h3>\n<p>#pragma once<br \/>\n#include &lt;iostream&gt;<br \/>\ntemplate&lt;class K&gt;<br \/>\nclass BSTNode<br \/>\n{<br \/>\npublic:<br \/>\nBSTNode() &#061; default;<br \/>\nBSTNode(const K&amp; _key)<br \/>\n:_val(_key)<br \/>\n, _left(nullptr)<br \/>\n, _right(nullptr)<br \/>\n{<\/p>\n<p>}<\/p>\n<p>K _val &#061; 0;<br \/>\nBSTNode&lt;K&gt;* _left &#061; nullptr;<br \/>\nBSTNode&lt;K&gt;* _right &#061; nullptr;<br \/>\n};<br \/>\n\/\/<\/p>\n<p>template&lt;class K&gt;<br \/>\nclass BSTree<br \/>\n{<br \/>\nusing Node &#061; BSTNode&lt;K&gt;;<\/p>\n<p>\/\/typedef BSTNode&lt;K&gt; Node;<br \/>\npublic:<br \/>\nbool insert(const K&amp; key);<br \/>\nbool find(const K&amp; key);<br \/>\nbool erase(const K&amp; key);<br \/>\nvoid Print();<br \/>\nBSTree&lt;K&gt;&amp; operator&#061;(BSTree&lt;K&gt; bst);<\/p>\n<p>BSTree() &#061; default;<\/p>\n<p>BSTree(const BSTree&amp; bst)<br \/>\n{<br \/>\n_root &#061; Creat(bst._root);<br \/>\n}<\/p>\n<p>~BSTree()<br \/>\n{<br \/>\nDestroy(_root);<br \/>\n}<\/p>\n<p>private:<br \/>\nNode* Creat(Node* root);<br \/>\nvoid Print(Node* root);<br \/>\nvoid Destroy(Node* root);<br \/>\nNode* _root &#061; nullptr;<br \/>\n};<\/p>\n<p>template&lt;class K&gt;<br \/>\nbool BSTree&lt;K&gt;::insert(const K&amp; key)<br \/>\n{<br \/>\nif (_root &#061;&#061; nullptr)<br \/>\n{<br \/>\nNode* node &#061; new Node(key);<br \/>\n_root &#061; node;<br \/>\nreturn true;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nNode* cur &#061; _root;<br \/>\nNode* parent &#061; nullptr;<br \/>\nwhile (cur)<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\nif (cur-&gt;_val &gt; key)<br \/>\ncur &#061; cur-&gt;_left;<br \/>\nelse if (cur-&gt;_val &lt; key)<br \/>\ncur &#061; cur-&gt;_right;<br \/>\nelse<br \/>\nreturn false;<br \/>\n}<br \/>\nNode* node &#061; new Node(key);<br \/>\nif (parent-&gt;_val &gt; key)<br \/>\nparent-&gt;_left &#061; node;<br \/>\nelse<br \/>\nparent-&gt;_right &#061; node;<br \/>\nreturn true;<br \/>\n}<br \/>\n}<\/p>\n<p>template&lt;class K&gt;<br \/>\nvoid BSTree&lt;K&gt;::Destroy(Node* root)<br \/>\n{<br \/>\nif (root &#061;&#061; nullptr)<br \/>\nreturn;<br \/>\nDestroy(root-&gt;_left);<br \/>\nDestroy(root-&gt;_right);<br \/>\ndelete root;<br \/>\n}<\/p>\n<p>template&lt;class K&gt;<br \/>\nvoid BSTree&lt;K&gt;::Print()<br \/>\n{<br \/>\nPrint(_root);<br \/>\n}<\/p>\n<p>template&lt;class K&gt;<br \/>\nvoid BSTree&lt;K&gt;::Print(Node* root)<br \/>\n{<br \/>\nif (root &#061;&#061; nullptr)<br \/>\nreturn;<br \/>\nPrint(root-&gt;_left);<br \/>\nstd::cout &lt;&lt; root-&gt;_val &lt;&lt; &#034; &#034;;<br \/>\nPrint(root-&gt;_right);<br \/>\n}<\/p>\n<p>template&lt;class K&gt;<br \/>\nbool BSTree&lt;K&gt;::find(const K&amp; key)<br \/>\n{<br \/>\nif (_root &#061;&#061; nullptr)<br \/>\nreturn false;<br \/>\nNode* cur &#061; _root;<br \/>\nwhile (cur)<br \/>\n{<br \/>\nif (cur-&gt;_val &gt; key)<br \/>\ncur &#061; cur-&gt;_left;<br \/>\nelse if (cur-&gt;_val &lt; key)<br \/>\ncur &#061; cur-&gt;_right;<br \/>\nelse<br \/>\nreturn true;<br \/>\n}<br \/>\nreturn false;<br \/>\n}<\/p>\n<p>template&lt;class K&gt;<br \/>\nbool BSTree&lt;K&gt;::erase(const K&amp; key)<br \/>\n{<br \/>\nif (_root &#061;&#061; nullptr)<br \/>\nreturn false;<br \/>\nNode* cur &#061; _root;<br \/>\nNode* parent &#061; nullptr;<br \/>\nwhile (cur)<br \/>\n{<br \/>\nif (cur-&gt;_val &gt; key)<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\ncur &#061; cur-&gt;_left;<br \/>\n}<br \/>\nelse if (cur-&gt;_val &lt; key)<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\ncur &#061; cur-&gt;_right;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (cur-&gt;_left &#061;&#061; nullptr)<br \/>\n{<br \/>\nif (cur &#061;&#061; _root)<br \/>\n{<br \/>\n_root &#061; cur-&gt;_right;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (parent-&gt;_right &#061;&#061; cur)<br \/>\nparent-&gt;_right &#061; cur-&gt;_right;<br \/>\nelse<br \/>\nparent-&gt;_left &#061; cur-&gt;_right;<br \/>\n}<br \/>\ndelete cur;<br \/>\n}<br \/>\nelse if (cur-&gt;_right &#061;&#061; nullptr)<br \/>\n{<br \/>\nif (cur &#061;&#061; _root)<br \/>\n{<br \/>\n_root &#061; cur-&gt;_left;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (parent-&gt;_right &#061;&#061; cur)<br \/>\nparent-&gt;_right &#061; cur-&gt;_left;<br \/>\nelse<br \/>\nparent-&gt;_left &#061; cur-&gt;_left;<br \/>\n}<br \/>\ndelete cur;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nNode* sparent &#061; cur;<br \/>\nNode* scur &#061; cur-&gt;_right;<br \/>\nwhile (scur-&gt;_left)<br \/>\n{<br \/>\nsparent &#061; scur;<br \/>\nscur &#061; scur-&gt;_left;<br \/>\n}<br \/>\ncur-&gt;_val &#061; scur-&gt;_val;<br \/>\nif (sparent &#061;&#061; cur)<br \/>\nsparent-&gt;_right &#061; scur-&gt;_right;<br \/>\nelse<br \/>\nsparent-&gt;_left &#061; scur-&gt;_right;<br \/>\ndelete scur;<br \/>\nbreak;<br \/>\n}<br \/>\nreturn true;<br \/>\n}<br \/>\n}<br \/>\nreturn false;<br \/>\n}<\/p>\n<p>template&lt;class K&gt;<br \/>\ntypename BSTree&lt;K&gt;::Node* BSTree&lt;K&gt;::Creat(Node* root)<br \/>\n{<br \/>\nif (root &#061;&#061; nullptr)<br \/>\nreturn nullptr;<br \/>\nNode* cur &#061; new Node(root-&gt;_val);<br \/>\ncur-&gt;_left &#061; Creat(root-&gt;_left);<br \/>\ncur-&gt;_right &#061; Creat(root-&gt;_right);<br \/>\nreturn cur;<br \/>\n}<\/p>\n<p>template&lt;class K&gt;<br \/>\nBSTree&lt;K&gt;&amp; BSTree&lt;K&gt;::operator&#061;(BSTree&lt;K&gt; bst)<br \/>\n{<br \/>\nstd::swap(_root, bst._root);<br \/>\nreturn *this;<br \/>\n}<\/p>\n<hr \/>\n<h2 id=\"7.%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91key%E5%92%8Ckey%2Fvalue%E4%BD%BF%E7%94%A8%E5%9C%BA%E6%99%AF\">7.\u4e8c\u53c9\u641c\u7d22\u6811key\u548ckey\/value\u4f7f\u7528\u573a\u666f<\/h2>\n<p>\u4e8c\u53c9\u641c\u7d22\u6811\u4f7f\u7528\u4e3b\u8981\u662f\u4fe9\u4e2a\u573a\u666f&#xff0c;key\u641c\u7d22\u573a\u666f\u548ckey\/value\u641c\u7d22\u573a\u666f<\/p>\n<\/p>\n<h3 id=\"7.1.key%E6%90%9C%E7%B4%A2%E5%9C%BA%E6%99%AF%EF%BC%88%E5%AF%B9%E5%BA%94set%E5%AE%B9%E5%99%A8%EF%BC%89\">7.1.key\u641c\u7d22\u573a\u666f&#xff08;\u5bf9\u5e94set\u5bb9\u5668&#xff09;<\/h3>\n<p>\u53ea\u6709 key \u4f5c\u4e3a\u5173\u952e\u7801&#xff0c;\u7ed3\u6784\u4e2d\u53ea\u9700\u8981\u5b58\u50a8 key \u5373\u53ef&#xff0c;\u5173\u952e\u7801\u5373\u4e3a\u9700\u8981\u641c\u7d22\u5230\u7684\u503c&#xff08;\u4e5f\u5c31\u662f\u6211\u4eec\u4e0a\u9762\u5b9e\u73b0\u7684\u90a3\u79cdBST&#xff09;&#xff0c;\u641c\u7d22\u573a\u666f\u53ea\u9700\u8981\u5224\u65ad key \u5728\u4e0d\u5728\u3002key \u7684\u641c\u7d22\u573a\u666f\u5b9e\u73b0\u7684\u4e8c\u53c9\u6811\u641c\u7d22\u6811\u652f\u6301\u589e\u5220\u67e5&#xff0c;\u4f46\u662f\u4e0d\u652f\u6301\u4fee\u6539&#xff0c;\u4fee\u6539 key \u7834\u574f\u641c\u7d22\u6811\u7ed3\u6784\u4e86\u3002<\/p>\n<p>\u573a\u666f 1&#xff1a;\u5c0f\u533a\u65e0\u4eba\u503c\u5b88\u8f66\u5e93&#xff0c;\u5c0f\u533a\u8f66\u5e93\u4e70\u4e86\u8f66\u4f4d\u7684\u4e1a\u4e3b\u8f66\u624d\u80fd\u8fdb\u5c0f\u533a&#xff0c;\u90a3\u4e48\u7269\u4e1a\u4f1a\u628a\u4e70\u4e86\u8f66\u4f4d\u7684\u4e1a\u4e3b\u7684\u8f66\u724c\u53f7\u5f55\u5165\u540e\u53f0\u7cfb\u7edf&#xff0c;\u8f66\u8f86\u8fdb\u5165\u65f6\u626b\u63cf\u8f66\u724c\u5728\u4e0d\u5728\u7cfb\u7edf\u4e2d&#xff0c;\u5728\u5219\u62ac\u6746&#xff0c;\u4e0d\u5728\u5219\u63d0\u793a\u975e\u672c\u5c0f\u533a\u8f66\u8f86&#xff0c;\u65e0\u6cd5\u8fdb\u5165\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"421\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154124-6a75fca431420.png\" width=\"629\" \/><\/p>\n<p>\u573a\u666f 2&#xff1a;\u68c0\u67e5\u4e00\u7bc7\u82f1\u6587\u6587\u7ae0\u5355\u8bcd\u62fc\u5199\u662f\u5426\u6b63\u786e&#xff0c;\u5c06\u8bcd\u5e93\u4e2d\u6240\u6709\u5355\u8bcd\u653e\u5165\u4e8c\u53c9\u641c\u7d22\u6811&#xff0c;\u8bfb\u53d6\u6587\u7ae0\u4e2d\u7684\u5355\u8bcd&#xff0c;\u67e5\u627e\u662f\u5426\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u4e2d&#xff0c;\u4e0d\u5728\u5219\u6ce2\u6d6a\u7ebf\u6807\u7ea2\u63d0\u793a\u3002&#xff08;\u53ef\u4ee5\u628aVS\u6211\u4eec\u8f93\u9519\u5173\u952e\u8bcd\u7206\u7ea2\u7406\u89e3\u6210\u8fd9\u6837&#xff09;<\/p>\n<\/p>\n<p><span style=\"color:#be191c\">key\u641c\u7d22\u573a\u666f\u7b80\u5355\u8bf4\u5c31\u662f\u5728\u4e0d\u5728&#xff08;\u4e5f\u5c31\u662f\u5bf9\u5e94\u6211\u4eec\u4e4b\u540e\u7684set\u5bb9\u5668&#xff09;<\/span><\/p>\n<\/p>\n<h3 id=\"7.2.key%2Fvalue%E6%90%9C%E7%B4%A2%E5%9C%BA%E6%99%AF%EF%BC%88%E5%AF%B9%E5%BA%94map%E5%AE%B9%E5%99%A8%EF%BC%89\">7.2.key\/value\u641c\u7d22\u573a\u666f&#xff08;\u5bf9\u5e94map\u5bb9\u5668&#xff09;<\/h3>\n<p>\u6bcf\u4e00\u4e2a\u5173\u952e\u7801 key&#xff0c;\u90fd\u6709\u4e0e\u4e4b\u5bf9\u5e94\u7684\u503c value&#xff0c;value \u53ef\u4ee5\u4efb\u610f\u7c7b\u578b\u5bf9\u8c61\u3002\u6811\u7684\u7ed3\u6784\u4e2d (\u7ed3\u70b9) \u9664\u4e86\u9700\u8981\u5b58\u50a8 key \u8fd8\u8981\u5b58\u50a8\u5bf9\u5e94\u7684 value&#xff0c;\u589e \/ \u5220 \/ \u67e5\u8fd8\u662f\u4ee5 key \u4e3a\u5173\u952e\u5b57\u8d70\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u89c4\u5219\u8fdb\u884c\u6bd4\u8f83&#xff0c;\u53ef\u4ee5\u5feb\u901f\u67e5\u627e\u5230 key \u5bf9\u5e94\u7684 value\u3002key\/value \u7684\u641c\u7d22\u573a\u666f\u5b9e\u73b0\u7684\u4e8c\u53c9\u6811\u641c\u7d22\u6811\u652f\u6301\u4fee\u6539&#xff0c;\u4f46\u662f\u4e0d\u652f\u6301\u4fee\u6539 key&#xff0c;\u4fee\u6539 key \u7834\u574f\u641c\u7d22\u6811\u6027\u8d28\u4e86&#xff0c;<span style=\"color:#be191c\">\u53ef\u4ee5\u4fee\u6539 value<\/span>\u3002<\/p>\n<p>\u573a\u666f 1&#xff1a;\u7b80\u5355\u4e2d\u82f1\u4e92\u8bd1\u5b57\u5178&#xff0c;\u6811\u7684\u7ed3\u6784\u4e2d (\u7ed3\u70b9) \u5b58\u50a8 key (\u82f1\u6587) \u548c value (\u4e2d\u6587)&#xff0c;\u641c\u7d22\u65f6\u8f93\u5165\u82f1\u6587&#xff0c;\u5219\u540c\u65f6\u67e5\u627e\u5230\u4e86\u82f1\u6587\u5bf9\u5e94\u7684\u4e2d\u6587\u3002<\/p>\n<p>\u573a\u666f 2&#xff1a;\u5546\u573a\u65e0\u4eba\u503c\u5b88\u8f66\u5e93&#xff0c;\u5165\u53e3\u8fdb\u573a\u65f6\u626b\u63cf\u8f66\u724c&#xff0c;\u8bb0\u5f55\u8f66\u724c\u548c\u5165\u573a\u65f6\u95f4&#xff0c;\u51fa\u53e3\u79bb\u573a\u65f6&#xff0c;\u626b\u63cf\u8f66\u724c&#xff0c;\u67e5\u627e\u5165\u573a\u65f6\u95f4&#xff0c;\u7528\u5f53\u524d\u65f6\u95f4\u2011\u5165\u573a\u65f6\u95f4\u8ba1\u7b97\u51fa\u505c\u8f66\u65f6\u957f&#xff0c;\u8ba1\u7b97\u51fa\u505c\u8f66\u8d39\u7528&#xff0c;\u7f34\u8d39\u540e\u62ac\u6746&#xff0c;\u8f66\u8f86\u79bb\u573a\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"463\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154124-6a75fca450014.png\" width=\"620\" \/><\/p>\n<p>\u573a\u666f 3&#xff1a;\u7edf\u8ba1\u4e00\u7bc7\u6587\u7ae0\u4e2d\u5355\u8bcd\u51fa\u73b0\u7684\u6b21\u6570&#xff0c;\u8bfb\u53d6\u4e00\u4e2a\u5355\u8bcd&#xff0c;\u67e5\u627e\u5355\u8bcd\u662f\u5426\u5b58\u5728&#xff0c;\u4e0d\u5b58\u5728\u8fd9\u4e2a\u8bf4\u660e\u7b2c\u4e00\u6b21\u51fa\u73b0&#xff0c;&#xff08;\u5355\u8bcd&#xff0c;1&#xff09;&#xff0c;\u5355\u8bcd\u5b58\u5728&#xff0c;\u5219 &#043;&#043; \u5355\u8bcd\u5bf9\u5e94\u7684\u6b21\u6570\u3002<\/p>\n<\/p>\n<h3 id=\"7.3.key%2Fvalue%E4%BA%8C%E5%8F%89%E6%90%9C%E7%B4%A2%E6%A0%91%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0\">7.3.key\/value\u4e8c\u53c9\u641c\u7d22\u6811\u4ee3\u7801\u5b9e\u73b0<\/h3>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u8fd9\u4e2a\u5b9e\u73b0\u5176\u5b9e\u5c31\u662f\u5728\u539f\u5148\u7684key\u641c\u7d22\u573a\u666f\u7684\u57fa\u7840\u4e0a\u6539\u6539\u5c31\u884c\u4e86&#xff0c;\u8fd9\u91cc\u6211\u5c31\u76f4\u63a5\u653e\u4ee3\u7801\u4e86<\/p>\n<p>namespace key_value<br \/>\n{<br \/>\ntemplate&lt;class K,class V&gt;<br \/>\nclass BSTNode<br \/>\n{<br \/>\npublic:<br \/>\nBSTNode() &#061; default;<br \/>\nBSTNode(const K&amp; key, const V&amp; value)<br \/>\n:_key(key)<br \/>\n,_value(value)<br \/>\n, _left(nullptr)<br \/>\n, _right(nullptr)<br \/>\n{<\/p>\n<p>}<\/p>\n<p>K _key;<br \/>\nV _value;<br \/>\nBSTNode&lt;K, V&gt;* _left &#061; nullptr;<br \/>\nBSTNode&lt;K, V&gt;* _right &#061; nullptr;<br \/>\n};<br \/>\n\/\/<\/p>\n<p>template&lt;class K, class V&gt;<br \/>\nclass BSTree<br \/>\n{<br \/>\nusing Node &#061; BSTNode&lt;K, V&gt;;<\/p>\n<p>\/\/typedef BSTNode&lt;K&gt; Node;<br \/>\npublic:<br \/>\nbool insert(const K&amp; key, const V&amp; value);<br \/>\nNode* find(const K&amp; key);<br \/>\nbool erase(const K&amp; key);<br \/>\nvoid Print();<br \/>\nBSTree&lt;K,V&gt;&amp; operator&#061;(BSTree&lt;K,V&gt; bst);<\/p>\n<p>BSTree() &#061; default;<\/p>\n<p>BSTree(const BSTree&amp; bst)<br \/>\n{<br \/>\n_root &#061; Creat(bst._root);<br \/>\n}<\/p>\n<p>~BSTree()<br \/>\n{<br \/>\nDestroy(_root);<br \/>\n}<\/p>\n<p>private:<br \/>\nNode* Creat(Node* root);<br \/>\nvoid Print(Node* root);<br \/>\nvoid Destroy(Node* root);<br \/>\nNode* _root &#061; nullptr;<br \/>\n};<\/p>\n<p>template&lt;class K, class V&gt;<br \/>\nbool BSTree&lt;K,V&gt;::insert(const K&amp; key, const V&amp; value)<br \/>\n{<br \/>\nif (_root &#061;&#061; nullptr)<br \/>\n{<br \/>\nNode* node &#061; new Node(key, value);<br \/>\n_root &#061; node;<br \/>\nreturn true;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nNode* cur &#061; _root;<br \/>\nNode* parent &#061; nullptr;<br \/>\nwhile (cur)<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\nif (cur-&gt;_key &gt; key)<br \/>\ncur &#061; cur-&gt;_left;<br \/>\nelse if (cur-&gt;_key &lt; key)<br \/>\ncur &#061; cur-&gt;_right;<br \/>\nelse<br \/>\nreturn false;<br \/>\n}<br \/>\nNode* node &#061; new Node(key, value);<br \/>\nif (parent-&gt;_key &gt; key)<br \/>\nparent-&gt;_left &#061; node;<br \/>\nelse<br \/>\nparent-&gt;_right &#061; node;<br \/>\nreturn true;<br \/>\n}<br \/>\n}<\/p>\n<p>template&lt;class K, class V&gt;<br \/>\nvoid BSTree&lt;K, V&gt;::Destroy(Node* root)<br \/>\n{<br \/>\nif (root &#061;&#061; nullptr)<br \/>\nreturn;<br \/>\nDestroy(root-&gt;_left);<br \/>\nDestroy(root-&gt;_right);<br \/>\ndelete root;<br \/>\n}<\/p>\n<p>template&lt;class K, class V&gt;<br \/>\nvoid BSTree&lt;K, V&gt;::Print()<br \/>\n{<br \/>\nPrint(_root);<br \/>\n}<\/p>\n<p>template&lt;class K, class V&gt;<br \/>\nvoid BSTree&lt;K, V&gt;::Print(Node* root)<br \/>\n{<br \/>\nif (root &#061;&#061; nullptr)<br \/>\nreturn;<br \/>\nPrint(root-&gt;_left);<br \/>\nstd::cout &lt;&lt; root-&gt;_key &lt;&lt; &#034;-&gt;&#034; &lt;&lt; root-&gt;_value &lt;&lt; &#034; &#034;;<br \/>\nPrint(root-&gt;_right);<br \/>\n}<\/p>\n<p>template&lt;class K, class V&gt;<br \/>\ntypename BSTree&lt;K, V&gt;::Node* BSTree&lt;K, V&gt;::find(const K&amp; key)<br \/>\n{<br \/>\nif (_root &#061;&#061; nullptr)<br \/>\nreturn nullptr;<br \/>\nNode* cur &#061; _root;<br \/>\nwhile (cur)<br \/>\n{<br \/>\nif (cur-&gt;_key &gt; key)<br \/>\ncur &#061; cur-&gt;_left;<br \/>\nelse if (cur-&gt;_key &lt; key)<br \/>\ncur &#061; cur-&gt;_right;<br \/>\nelse<br \/>\nreturn cur;<br \/>\n}<br \/>\nreturn nullptr;<br \/>\n}<\/p>\n<p>template&lt;class K, class V&gt;<br \/>\nbool BSTree&lt;K, V&gt;::erase(const K&amp; key)<br \/>\n{<br \/>\nif (_root &#061;&#061; nullptr)<br \/>\nreturn false;<br \/>\nNode* cur &#061; _root;<br \/>\nNode* parent &#061; nullptr;<br \/>\nwhile (cur)<br \/>\n{<br \/>\nif (cur-&gt;_key &gt; key)<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\ncur &#061; cur-&gt;_left;<br \/>\n}<br \/>\nelse if (cur-&gt;_key &lt; key)<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\ncur &#061; cur-&gt;_right;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (cur-&gt;_left &#061;&#061; nullptr)<br \/>\n{<br \/>\nif (cur &#061;&#061; _root)<br \/>\n{<br \/>\n_root &#061; cur-&gt;_right;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (parent-&gt;_right &#061;&#061; cur)<br \/>\nparent-&gt;_right &#061; cur-&gt;_right;<br \/>\nelse<br \/>\nparent-&gt;_left &#061; cur-&gt;_right;<br \/>\n}<br \/>\ndelete cur;<br \/>\n}<br \/>\nelse if (cur-&gt;_right &#061;&#061; nullptr)<br \/>\n{<br \/>\nif (cur &#061;&#061; _root)<br \/>\n{<br \/>\n_root &#061; cur-&gt;_left;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nif (parent-&gt;_right &#061;&#061; cur)<br \/>\nparent-&gt;_right &#061; cur-&gt;_left;<br \/>\nelse<br \/>\nparent-&gt;_left &#061; cur-&gt;_left;<br \/>\n}<br \/>\ndelete cur;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nNode* sparent &#061; cur;<br \/>\nNode* scur &#061; cur-&gt;_right;<br \/>\nwhile (scur-&gt;_left)<br \/>\n{<br \/>\nsparent &#061; scur;<br \/>\nscur &#061; scur-&gt;_left;<br \/>\n}<br \/>\ncur-&gt;_key &#061; scur-&gt;_key;<br \/>\ncur-&gt;_value &#061; scur-&gt;_value;<br \/>\nif (sparent &#061;&#061; cur)<br \/>\nsparent-&gt;_right &#061; scur-&gt;_right;<br \/>\nelse<br \/>\nsparent-&gt;_left &#061; scur-&gt;_right;<br \/>\ndelete scur;<br \/>\nbreak;<br \/>\n}<br \/>\nreturn true;<br \/>\n}<br \/>\n}<br \/>\nreturn false;<br \/>\n}<\/p>\n<p>template&lt;class K, class V&gt;<br \/>\ntypename BSTree&lt;K, V&gt;::Node* BSTree&lt;K, V&gt;::Creat(Node* root)<br \/>\n{<br \/>\nif (root &#061;&#061; nullptr)<br \/>\nreturn nullptr;<br \/>\nNode* cur &#061; new Node(root-&gt;_key, root-&gt;_value);<br \/>\ncur-&gt;_left &#061; Creat(root-&gt;_left);<br \/>\ncur-&gt;_right &#061; Creat(root-&gt;_right);<br \/>\nreturn cur;<br \/>\n}<\/p>\n<p>template&lt;class K, class V&gt;<br \/>\nBSTree&lt;K, V&gt;&amp; BSTree&lt;K, V&gt;::operator&#061;(BSTree&lt;K, V&gt; bst)<br \/>\n{<br \/>\nstd::swap(_root, bst._root);<br \/>\nreturn *this;<br \/>\n}<br \/>\n} <\/p>\n<p>\u5b9e\u73b0\u5b8c\u4e86\u540e\u53ef\u4ee5\u7528\u4e0b\u9762\u4fe9\u4efd\u6d4b\u8bd5\u4ee3\u7801\u6d4b\u8bd5\u4e00\u4e0b\u00a0<\/p>\n<p>#define _CRT_SECURE_NO_WARNINGS<br \/>\n#include &#034;Binary Search Tree.h&#034;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<br \/>\nint main()<br \/>\n{<br \/>\nkey_value::BSTree&lt;string, string&gt; dict;<br \/>\ndict.insert(&#034;left&#034;, &#034;\u5de6\u8fb9&#034;);<br \/>\ndict.insert(&#034;right&#034;, &#034;\u53f3\u8fb9&#034;);<br \/>\ndict.insert(&#034;insert&#034;, &#034;\u63d2\u5165&#034;);<br \/>\ndict.insert(&#034;string&#034;, &#034;\u5b57\u7b26\u4e32&#034;);<br \/>\nstring str;<br \/>\nwhile (cin &gt;&gt; str)<br \/>\n{<br \/>\nauto ret &#061; dict.find(str);<br \/>\nif (ret)<br \/>\n{<br \/>\ncout &lt;&lt; &#034;-&gt;&#034; &lt;&lt; ret-&gt;_value &lt;&lt; endl;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\ncout &lt;&lt; &#034;\u65e0\u6b64\u5355\u8bcd&#xff0c;\u8bf7\u91cd\u65b0\u8f93\u5165&#034; &lt;&lt; endl;<br \/>\n}<br \/>\n}<br \/>\nreturn 0;<br \/>\n}<br \/>\n#define _CRT_SECURE_NO_WARNINGS<br \/>\n#include &#034;Binary Search Tree.h&#034;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<\/p>\n<p>int main()<br \/>\n{<br \/>\nstring arr[] &#061; { &#034;\u82f9\u679c&#034;, &#034;\u897f\u74dc&#034;, &#034;\u82f9\u679c&#034;, &#034;\u897f\u74dc&#034;, &#034;\u82f9\u679c&#034;, &#034;\u82f9\u679c&#034;, &#034;\u897f\u74dc&#034;, &#034;\u82f9\u679c&#034;, &#034;\u9999\u8549&#034;, &#034;\u82f9\u679c&#034;, &#034;\u9999\u8549&#034; };<br \/>\nkey_value::BSTree&lt;string, int&gt; countTree;<br \/>\nfor (const auto&amp; str : arr)<br \/>\n{<br \/>\n\/\/ \u5148\u67e5\u627e\u2f54\u679c\u5728\u4e0d\u5728\u641c\u7d22\u6811\u4e2d<br \/>\n\/\/ 1\u3001\u4e0d\u5728&#xff0c;\u8bf4\u660e\u2f54\u679c\u7b2c\u2f00\u6b21\u51fa\u73b0&#xff0c;\u5219\u63d2\u2f0a&lt;\u2f54\u679c, 1&gt;<br \/>\n\/\/ 2\u3001\u5728&#xff0c;\u5219\u67e5\u627e\u5230\u7684\u7ed3\u70b9\u4e2d\u2f54\u679c\u5bf9\u5e94\u7684\u6b21\u6570&#043;&#043;<br \/>\n\/\/BSTreeNode&lt;string, int&gt;* ret &#061; countTree.Find(str);<br \/>\nauto ret &#061; countTree.find(str);<br \/>\nif (ret &#061;&#061; NULL)<br \/>\n{<br \/>\ncountTree.insert(str, 1);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nret-&gt;_value&#043;&#043;;<br \/>\n}<br \/>\n}<br \/>\ncountTree.Print();<br \/>\nreturn 0;<br \/>\n} <\/p>\n<hr \/>\n<h2 id=\"%E7%BB%93%E8%AF%AD%EF%BC%9A\">\u7ed3\u8bed&#xff1a;<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u90a3\u4e48&#xff0c;\u7528C&#043;&#043;\u5b9e\u73b0\u7684\u9ad8\u9636\u6570\u636e\u7ed3\u6784\u7684\u4e8c\u53c9\u641c\u7d22\u6811\u90e8\u5206\u7684\u5185\u5bb9\u5c31\u5168\u90e8\u8bb2\u89e3\u5b8c\u6bd5\u5566&#xff0c;\u5e0c\u671b\u4ee5\u4e0a\u5185\u5bb9\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9&#xff0c;\u611f\u8c22\u89c2\u770b&#xff0c;\u82e5\u89c9\u5f97\u5199\u7684\u8fd8\u53ef\u4ee5&#xff0c;\u53ef\u4ee5\u5206\u4eab\u7ed9\u670b\u53cb\u4e00\u8d77\u6765\u770b\u54e6&#xff0c;\u6bd5\u7adf\u4e00\u8d77\u8fdb\u6b65\u66f4\u6709\u52a8\u529b\u561b&#xff0c;\u5f53\u7136\u80fd\u5173\u6ce8\u4e00\u4e0b\u5c31\u66f4\u597d\u5566\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"648\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154124-6a75fca471222.png\" width=\"648\" \/><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55<br \/>\n\u5f15\u8a00&#xff1a;<br \/>\n1.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6982\u5ff5<br \/>\n2.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6027\u80fd\u5206\u6790<br \/>\n3.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u63d2\u5165\u539f\u7406<br \/>\n4.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u67e5\u627e\u539f\u7406<br \/>\n5.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5220\u9664\u539f\u7406<br \/>\n6.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5b9e\u73b0<br \/>\n6.1.\u6784\u5efa\u521d\u67b6\u6784<br \/>\n\u62d3\u5c55&#xff1a;using\u5173\u952e\u5b57<br \/>\n6.2.\u63d2\u5165\u5b9e\u73b0&#xff08;Insert&#xff09;<br \/>\n6.3.\u6790\u6784\u5b9e\u73b0<br \/>\n6.4.Print\u5b9e\u73b0&#xff08;\u6d4b\u8bd5&#xff09;<br \/>\n6.5.\u67e5\u627e\u5b9e\u73b0&#xff08;find&#xff09;<br \/>\n6.6.\u5220\u9664\u5b9e\u73b0&amp;#<\/p>\n","protected":false},"author":2,"featured_media":91549,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10187,10448,10449,55,190,1813],"topic":[],"class_list":["post-91565","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-codingplan","tag-bst","tag-10449","tag-c","tag-190","tag-1813"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++ \u9ad8\u9636\u6570\u636e\u7ed3\u6784\uff1a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u4e07\u5b57\u8be6\u89e3 | \u539f\u7406\u3001\u589e\u5220\u67e5\u3001key \u4e0e key\u2011value \u53cc\u7248\u672c\u5b9e\u73b0\u3001\u770b\u61c2 set\/map \u5e95\u5c42 - \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\/91565.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ \u9ad8\u9636\u6570\u636e\u7ed3\u6784\uff1a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u4e07\u5b57\u8be6\u89e3 | \u539f\u7406\u3001\u589e\u5220\u67e5\u3001key \u4e0e key\u2011value \u53cc\u7248\u672c\u5b9e\u73b0\u3001\u770b\u61c2 set\/map \u5e95\u5c42 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 \u5f15\u8a00&#xff1a; 1.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6982\u5ff5 2.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6027\u80fd\u5206\u6790 3.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u63d2\u5165\u539f\u7406 4.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u67e5\u627e\u539f\u7406 5.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5220\u9664\u539f\u7406 6.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5b9e\u73b0 6.1.\u6784\u5efa\u521d\u67b6\u6784 \u62d3\u5c55&#xff1a;using\u5173\u952e\u5b57 6.2.\u63d2\u5165\u5b9e\u73b0&#xff08;Insert&#xff09; 6.3.\u6790\u6784\u5b9e\u73b0 6.4.Print\u5b9e\u73b0&#xff08;\u6d4b\u8bd5&#xff09; 6.5.\u67e5\u627e\u5b9e\u73b0&#xff08;find&#xff09; 6.6.\u5220\u9664\u5b9e\u73b0&amp;#\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/91565.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-07T15:41:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154121-6a75fca1dd66e.png\" \/>\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=\"13 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/91565.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/91565.html\",\"name\":\"C++ \u9ad8\u9636\u6570\u636e\u7ed3\u6784\uff1a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u4e07\u5b57\u8be6\u89e3 | \u539f\u7406\u3001\u589e\u5220\u67e5\u3001key \u4e0e key\u2011value \u53cc\u7248\u672c\u5b9e\u73b0\u3001\u770b\u61c2 set\/map \u5e95\u5c42 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-07T15:41:25+00:00\",\"dateModified\":\"2026-08-07T15:41:25+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/91565.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/91565.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/91565.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ \u9ad8\u9636\u6570\u636e\u7ed3\u6784\uff1a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u4e07\u5b57\u8be6\u89e3 | \u539f\u7406\u3001\u589e\u5220\u67e5\u3001key \u4e0e key\u2011value \u53cc\u7248\u672c\u5b9e\u73b0\u3001\u770b\u61c2 set\/map \u5e95\u5c42\"}]},{\"@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":"C++ \u9ad8\u9636\u6570\u636e\u7ed3\u6784\uff1a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u4e07\u5b57\u8be6\u89e3 | \u539f\u7406\u3001\u589e\u5220\u67e5\u3001key \u4e0e key\u2011value \u53cc\u7248\u672c\u5b9e\u73b0\u3001\u770b\u61c2 set\/map \u5e95\u5c42 - \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\/91565.html","og_locale":"zh_CN","og_type":"article","og_title":"C++ \u9ad8\u9636\u6570\u636e\u7ed3\u6784\uff1a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u4e07\u5b57\u8be6\u89e3 | \u539f\u7406\u3001\u589e\u5220\u67e5\u3001key \u4e0e key\u2011value \u53cc\u7248\u672c\u5b9e\u73b0\u3001\u770b\u61c2 set\/map \u5e95\u5c42 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 \u5f15\u8a00&#xff1a; 1.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6982\u5ff5 2.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6027\u80fd\u5206\u6790 3.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u63d2\u5165\u539f\u7406 4.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u67e5\u627e\u539f\u7406 5.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5220\u9664\u539f\u7406 6.\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u5b9e\u73b0 6.1.\u6784\u5efa\u521d\u67b6\u6784 \u62d3\u5c55&#xff1a;using\u5173\u952e\u5b57 6.2.\u63d2\u5165\u5b9e\u73b0&#xff08;Insert&#xff09; 6.3.\u6790\u6784\u5b9e\u73b0 6.4.Print\u5b9e\u73b0&#xff08;\u6d4b\u8bd5&#xff09; 6.5.\u67e5\u627e\u5b9e\u73b0&#xff08;find&#xff09; 6.6.\u5220\u9664\u5b9e\u73b0&amp;#","og_url":"https:\/\/www.wsisp.com\/helps\/91565.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-07T15:41:25+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807154121-6a75fca1dd66e.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"13 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/91565.html","url":"https:\/\/www.wsisp.com\/helps\/91565.html","name":"C++ \u9ad8\u9636\u6570\u636e\u7ed3\u6784\uff1a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u4e07\u5b57\u8be6\u89e3 | \u539f\u7406\u3001\u589e\u5220\u67e5\u3001key \u4e0e key\u2011value \u53cc\u7248\u672c\u5b9e\u73b0\u3001\u770b\u61c2 set\/map \u5e95\u5c42 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-07T15:41:25+00:00","dateModified":"2026-08-07T15:41:25+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/91565.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/91565.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/91565.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++ \u9ad8\u9636\u6570\u636e\u7ed3\u6784\uff1a\u4e8c\u53c9\u641c\u7d22\u6811\uff08BST\uff09\u4e07\u5b57\u8be6\u89e3 | \u539f\u7406\u3001\u589e\u5220\u67e5\u3001key \u4e0e key\u2011value \u53cc\u7248\u672c\u5b9e\u73b0\u3001\u770b\u61c2 set\/map \u5e95\u5c42"}]},{"@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\/91565","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=91565"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/91565\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/91549"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=91565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=91565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=91565"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=91565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}