{"id":120508,"date":"2026-10-31T20:41:05","date_gmt":"2026-10-31T12:41:05","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/120508.html"},"modified":"2026-10-31T20:41:05","modified_gmt":"2026-10-31T12:41:05","slug":"c%e8%af%ad%e8%a8%80%e5%8e%9f%e7%90%86%e4%b8%8e%e5%ae%9e%e8%b7%b5%e4%ba%8c%e5%8d%81%e7%ba%a2%e9%bb%91%e6%a0%91%e7%9a%84%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/120508.html","title":{"rendered":"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u4e8c\u5341):\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0"},"content":{"rendered":"<p>\u672c\u7bc7\u76ee\u6807:<br \/>\n1.\u638c\u63e1\u7ea2\u9ed1\u6811\u7684\u6982\u5ff5\u4e0e\u67d3\u8272\u8fc7\u7a0b<\/p>\n<p>2.\u5b66\u4f1a\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0<\/p>\n<\/p>\n<p>\u6ce8\u610f&#xff1a;\u5b66\u4e60\u672c\u7247\u524d\u5fc5\u987b\u8981\u5b66\u4f1aAVL\u6811\u7684\u65cb\u8f6c\u3002<\/p>\n<\/p>\n<h2>\u4e00.\u7ea2\u9ed1\u6811\u7684\u6982\u5ff5<\/h2>\n<h3>1.\u6982\u5ff5<\/h3>\n<p>\u7ea2\u9ed1\u6811\u662f\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811&#xff0c;\u4ed6\u7684\u6bcf\u4e2a\u7ed3\u70b9\u589e\u52a0\u2f00\u4e2a\u5b58\u50a8\u4f4d\u6765\u8868\u793a\u7ed3\u70b9\u7684\u989c\u8272&#xff0c;\u53ef\u4ee5\u662f\u7ea2\u8272\u6216\u8005\u9ed1\u8272\u3002 \u901a\u8fc7\u5bf9\u4efb\u4f55\u4e00\u6761\u4ece\u6839\u5230\u53f6\u5b50\u7684\u8def\u5f84\u4e0a\u5404\u4e2a\u7ed3\u70b9\u7684\u989c\u8272\u8fdb\u884c\u7ea6\u675f&#xff0c;\u7ea2\u9ed1\u6811\u786e\u4fdd\u6ca1\u6709\u2f00\u6761\u8def\u5f84\u4f1a\u6bd4\u5176\u4ed6\u8def\u5f84\u957f\u51fa2\u500d&#xff0c;\u56e0\u800c\u662f\u63a5\u8fd1\u5e73\u8861\u7684\u3002<\/p>\n<p>\u5982\u56fe&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"960\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124046-6ae5e1ce7a6af.png\" width=\"1600\" \/><\/p>\n<h3>2.\u89c4\u5219<\/h3>\n<p>\u4e00\u68f5\u7ea2\u9ed1\u6811\u5fc5\u987b\u8981\u6ee1\u8db3\u4ee5\u4e0b\u7684\u89c4\u5219:<\/p>\n<p>&lt;1&gt;.\u6bcf\u4e2a\u7ed3\u70b9\u4e0d\u662f\u7ea2\u8272\u5c31\u662f\u9ed1\u8272<\/p>\n<p>&lt;2&gt;. \u6839\u7ed3\u70b9\u662f\u9ed1\u8272\u7684 <\/p>\n<p>&lt;3&gt;. \u5982\u679c\u2f00\u4e2a\u7ed3\u70b9\u662f\u7ea2\u8272\u7684&#xff0c;\u5219\u5b83\u7684\u4e24\u4e2a\u5b69\u5b50\u7ed3\u70b9\u5fc5\u987b\u662f\u9ed1\u8272\u7684&#xff0c;\u4e5f\u5c31\u662f\u8bf4\u4efb\u610f\u2f00\u6761\u8def\u5f84\u4e0d\u4f1a\u6709\u8fde\u7eed\u7684\u7ea2\u8272\u7ed3\u70b9\u3002 <\/p>\n<p>&lt;4&gt;. \u5bf9\u4e8e\u4efb\u610f\u2f00\u4e2a\u7ed3\u70b9&#xff0c;\u4ece\u8be5\u7ed3\u70b9\u5230\u5176\u6240\u6709NULL\u7ed3\u70b9\u7684\u7b80\u5355\u8def\u5f84\u4e0a&#xff0c;\u5747\u5305\u542b\u76f8\u540c\u6570\u91cf\u7684\u9ed1\u8272\u7ed3\u70b9<\/p>\n<p>\u9996\u5148\u5462&#xff0c;\u6211\u4eec\u5148\u770b\u4e00\u5f20\u56fe\u7247&#xff0c;\u770b\u770b\u8fd9\u5f20\u56fe\u7247\u4ece\u6839\u8282\u70b9\u5230NULL\u8282\u70b9\u4e0a\u6709\u51e0\u6761\u8def\u5f84&#xff1f;<\/p>\n<p>\u5982\u56fe&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1030\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124047-6ae5e1cf8cf6b.png\" width=\"1700\" \/><\/p>\n<p>\u5f88\u591a\u4eba\u7684\u7b2c\u4e00\u53cd\u5e94\u53ef\u80fd\u662f 4 \u6761&#xff0c;\u56e0\u4e3a\u56fe\u4e2d\u6709 15\u300125\u300135\u300150 \u56db\u4e2a\u53f6\u5b50\u8282\u70b9\u3002\u4f46\u8fd9\u6570\u7684\u662f\u4ece\u6839\u8282\u70b9\u5230\u666e\u901a\u53f6\u5b50\u8282\u70b9\u7684\u8def\u5f84&#xff0c;\u8fd8\u6ca1\u6709\u8d70\u5230 NULL\u3002<\/p>\n<p>\u6bcf\u4e2a\u53f6\u5b50\u8282\u70b9\u90fd\u6709\u4e24\u4e2a\u7a7a\u5b69\u5b50&#xff0c;\u56e0\u6b64&#xff0c;\u8fd9\u56db\u4e2a\u53f6\u5b50\u8282\u70b9\u5bf9\u5e94&#xff1a;8\u6761\u5230 NULL \u7684\u8def\u5f84\u3002<\/p>\n<p>\u6b64\u5916&#xff0c;\u8282\u70b9 10 \u7684\u5de6\u5b69\u5b50\u4e5f\u662f NULL&#xff0c;\u8fd8\u9700\u8981\u518d\u7b97\u4e00\u6761\u3002<\/p>\n<p>\u6240\u4ee5&#xff0c;\u8fd9\u68f5\u6811\u4ece\u6839\u8282\u70b9\u5230 NULL \u8282\u70b9&#xff0c;\u4e00\u5171\u6709&#xff1a;9\u6761<\/p>\n<p>\u7ea2\u9ed1\u6811\u6027\u8d28\u4e2d\u6240\u8bf4\u7684\u53f6\u5b50\u8282\u70b9&#xff0c;\u6307\u7684\u662f\u8fd9\u4e9b\u9ed1\u8272\u7684 NULL&#xff08;\u4e5f\u79f0 NIL&#xff09;\u8282\u70b9\u3002 \u4e3a\u4e86\u8ba9\u56fe\u66f4\u7b80\u6d01&#xff0c;\u5b83<\/p>\n<p>\u4eec\u901a\u5e38\u6ca1\u6709\u753b\u51fa\u6765&#xff0c;\u4f46\u5206\u6790\u8def\u5f84\u65f6\u4e0d\u80fd\u5ffd\u7565\u3002<\/p>\n<p>\u6240\u4ee5\u5b8c\u6574\u7684\u56fe\u5982\u4e0b&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1160\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124048-6ae5e1d04110f.png\" width=\"2000\" \/><\/p>\n<p>\u6ce8\u610f&#xff1a;\u901a\u5e38\u6bcf\u4e2aNULL\u8282\u70b9\u90fd\u662f\u9ed1\u8272\u7684&#xff0c;\u5982\u679c\u662f\u7ea2\u8272\u5bb9\u6613\u4e0e\u89c4\u5219\u4e09\u51b2\u7a81\u3002<\/p>\n<p>\u7136\u540e\u6211\u4eec\u63a5\u7740\u770b\u4e9b\u5176\u4ed6\u7684\u7ea2\u9ed1\u6811&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1100\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124049-6ae5e1d1045a7.png\" width=\"1800\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1100\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124049-6ae5e1d1d09f8.png\" width=\"2100\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"850\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124050-6ae5e1d2e840b.png\" width=\"1700\" \/><\/p>\n<h3 style=\"background-color:transparent\">3.\u6548\u7387<\/h3>\n<p>\u9996\u5148&#xff0c;\u6211\u4eec\u601d\u8003\u2f00\u4e0b&#xff0c;\u7ea2\u9ed1\u6811\u5982\u4f55\u786e\u4fdd\u6700\u957f\u8def\u5f84\u4e0d\u8d85\u8fc7\u6700\u77ed\u8def\u5f84\u76842\u500d\u7684&#xff1f;<\/p>\n<p>\u5173\u952e\u5728\u4e8e\u4e24\u6761\u6027\u8d28&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4ece\u6839\u8282\u70b9\u5230\u4efb\u610f NULL \u8282\u70b9\u7684\u8def\u5f84&#xff0c;\u5305\u542b\u7684\u9ed1\u8272\u8282\u70b9\u6570\u91cf\u76f8\u540c\u3002<\/p>\n<\/li>\n<li>\n<p>\u7ea2\u8272\u8282\u70b9\u4e0d\u80fd\u8fde\u7eed\u51fa\u73b0&#xff0c;\u5e76\u4e14\u6839\u8282\u70b9\u4e3a\u9ed1\u8272\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8bbe\u6bcf\u6761\u8def\u5f84\u4e0a\u90fd\u6709 bh \u4e2a\u9ed1\u8272\u8282\u70b9\u3002\u8fd9\u91cc\u7edf\u4e00\u4e0d\u8ba1 NULL&#xff0c;\u7528\u8def\u5f84\u4e0a\u7684\u975e\u7a7a\u8282\u70b9\u6570\u91cf\u8868\u793a\u8def\u5f84\u957f\u5ea6\u3002<\/p>\n<p>\u5bf9\u4e8e\u4efb\u610f\u4e00\u6761\u8def\u5f84&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u957f\u5ea6\u4e0b\u9650&#xff1a;\u5373\u4f7f\u6ca1\u6709\u7ea2\u8272\u8282\u70b9&#xff0c;\u4e5f\u6709 bh \u4e2a\u9ed1\u8272\u8282\u70b9&#xff0c;\u56e0\u6b64\u8def\u5f84\u957f\u5ea6\u81f3\u5c11\u4e3a bh\u3002<\/p>\n<\/li>\n<li>\n<p>\u957f\u5ea6\u4e0a\u9650&#xff1a;\u7531\u4e8e\u6839\u4e3a\u9ed1\u8272&#xff0c;\u4e14\u7ea2\u8272\u8282\u70b9\u4e0d\u80fd\u8fde\u7eed\u51fa\u73b0&#xff0c;\u7ea2\u8272\u8282\u70b9\u6570\u91cf\u4e0d\u4f1a\u8d85\u8fc7\u9ed1\u8272\u8282\u70b9\u6570\u91cf&#xff0c;\u56e0\u6b64\u8def\u5f84\u957f\u5ea6\u81f3\u591a\u4e3a 2bh\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6240\u4ee5&#xff0c;\u4efb\u610f\u8def\u5f84\u957f\u5ea6 h \u90fd\u6ee1\u8db3&#xff1a;bh \u2264 h \u2264 2 \u00d7 bh<\/p>\n<p>\u8bbe\u6700\u77ed\u8def\u5f84\u957f\u5ea6\u4e3a h_min&#xff0c;\u6700\u957f\u8def\u5f84\u957f\u5ea6\u4e3a h_max&#xff0c;\u5219&#xff1a;h_min \u2265 bh&#xff0c;h_max \u2264 2 \u00d7 bh<\/p>\n<p>\u56e0\u6b64&#xff1a;h_max \u2264 2 \u00d7 bh \u2264 2 \u00d7 h_min<\/p>\n<p>\u6240\u4ee5&#xff0c;\u6700\u957f\u8def\u5f84\u4e0d\u8d85\u8fc7\u6700\u77ed\u8def\u5f84\u7684\u4e24\u500d\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f&#xff1a;\u5168\u9ed1\u8def\u5f84\u548c\u7ea2\u9ed1\u4ea4\u66ff\u8def\u5f84\u53ea\u662f\u5206\u6790\u4e0a\u4e0b\u9650\u65f6\u8003\u8651\u7684\u6781\u7aef\u60c5\u51b5&#xff0c;\u5e76\u4e0d\u8981\u6c42\u6bcf\u68f5\u7ea2\u9ed1\u6811\u4e2d\u90fd\u5b58\u5728\u8fd9\u6837\u7684\u8def\u5f84\u3002<\/p>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u6211\u4eec\u8c08\u4e0b\u7ea2\u9ed1\u6811\u7684\u6548\u7387&#xff1a;<\/p>\n<p>\u5047\u8bbe\u7ea2\u9ed1\u6811\u4e2d\u6709 N \u4e2a\u975e\u7a7a\u8282\u70b9&#xff0c;\u6700\u77ed\u8def\u5f84\u957f\u5ea6\u4e3a h&#xff0c;\u6700\u957f\u8def\u5f84\u957f\u5ea6\u4e3a H\u3002\u8fd9\u91cc\u8def\u5f84\u957f\u5ea6\u7edf\u4e00\u6309\u4ece\u6839\u5230 NULL \u7ecf\u8fc7\u7684\u975e\u7a7a\u8282\u70b9\u6570\u8ba1\u7b97\u3002<\/p>\n<p>\u7531\u4e8e\u6700\u77ed\u8def\u5f84\u957f\u5ea6\u4e3a h&#xff0c;\u524d h \u5c42\u4e00\u5b9a\u662f\u6ee1\u7684&#xff0c;\u56e0\u6b64&#xff1a;N \u2265 2^h \u2212 1<\/p>\n<p>\u7531\u6b64\u5f97\u5230&#xff1a;h \u2264 log\u2082(N &#043; 1)<\/p>\n<p>\u53c8\u56e0\u4e3a\u7ea2\u9ed1\u6811\u7684\u6700\u957f\u8def\u5f84\u4e0d\u8d85\u8fc7\u6700\u77ed\u8def\u5f84\u7684\u4e24\u500d&#xff0c;\u6240\u4ee5&#xff1a;H \u2264 2h \u2264 2 \u00d7 log\u2082(N &#043; 1)<\/p>\n<p>\u56e0\u6b64&#xff0c;\u7ea2\u9ed1\u6811\u7684\u9ad8\u5ea6\u4e3a O(log N)&#xff0c;\u67e5\u627e\u3001\u63d2\u5165\u548c\u5220\u9664\u7684\u6700\u574f\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u90fd\u662f O(log N)\u3002\u5982\u679c\u9700\u8981\u4fee\u6539 value&#xff0c;\u5148\u6309 key \u67e5\u627e\u5373\u53ef&#xff1b;key \u4e0d\u80fd\u76f4\u63a5\u4fee\u6539&#xff0c;\u5426\u5219\u53ef\u80fd\u7834\u574f\u641c\u7d22\u6811\u7684\u6027\u8d28\u3002<\/p>\n<p>\u4e0e AVL \u6811\u76f8\u6bd4&#xff0c;\u7ea2\u9ed1\u6811\u5bf9\u5e73\u8861\u7684\u63a7\u5236\u66f4\u52a0\u95f4\u63a5&#xff1a;AVL \u6811\u901a\u8fc7\u5de6\u53f3\u5b50\u6811\u7684\u9ad8\u5ea6\u5dee\u7ef4\u6301\u5e73\u8861&#xff0c;\u7ea2\u9ed1\u6811\u5219\u901a\u8fc7\u989c\u8272\u7ea6\u675f&#xff0c;\u4fdd\u8bc1\u6700\u957f\u8def\u5f84\u4e0d\u8d85\u8fc7\u6700\u77ed\u8def\u5f84\u7684\u4e24\u500d\u3002<\/p>\n<p>\u4e24\u8005\u7684\u64cd\u4f5c\u590d\u6742\u5ea6\u90fd\u5c5e\u4e8e O(log N)&#xff0c;\u4f46\u7ea2\u9ed1\u6811\u5bf9\u5e73\u8861\u7684\u8981\u6c42\u66f4\u5bbd\u677e&#xff0c;\u8c03\u6574\u65f6\u53ef\u4ee5\u901a\u8fc7\u53d8\u8272\u548c\u65cb\u8f6c\u6062\u590d\u6027\u8d28\u3002\u9700\u8981\u6ce8\u610f&#xff0c;\u4e0d\u80fd\u7b80\u5355\u8ba4\u4e3a\u63d2\u5165\u76f8\u540c\u6570\u91cf\u7684\u8282\u70b9&#xff0c;\u7ea2\u9ed1\u6811\u7684\u65cb\u8f6c\u6b21\u6570\u5c31\u4e00\u5b9a\u6bd4 AVL \u6811\u5c11&#xff0c;\u5177\u4f53\u6b21\u6570\u8fd8\u4e0e\u63d2\u5165\u987a\u5e8f\u6709\u5173\u3002<\/p>\n<h2>\u4e8c.\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0<\/h2>\n<h3>1.\u7ed3\u6784<\/h3>\n<p>\/\/ \u679a\u4e3e\u503c\u8868\u793a\u989c\u8272<br \/>\nenum Colour<br \/>\n{<br \/>\n    RED,<br \/>\n    BLACK<br \/>\n};<br \/>\n\/\/ \u9ed8\u8ba4\u6309 key\/value \u7ed3\u6784\u5b9e\u73b0<br \/>\ntemplate&lt;class K, class V&gt;<br \/>\nstruct RBTreeNode<br \/>\n{<br \/>\n    pair&lt;K, V&gt; _kv;<br \/>\n    RBTreeNode&lt;K, V&gt;* _left;<br \/>\n    RBTreeNode&lt;K, V&gt;* _right;<\/p>\n<p>    \/\/ \u8c03\u6574\u6811\u7684\u5e73\u8861\u65f6&#xff0c;\u9700\u8981\u901a\u8fc7 parent \u6307\u9488\u627e\u5230\u7236\u8282\u70b9<br \/>\n    RBTreeNode&lt;K, V&gt;* _parent;<br \/>\n    Colour _col;<\/p>\n<p>    RBTreeNode(const pair&lt;K, V&gt;&amp; kv)<br \/>\n        : _kv(kv)<br \/>\n        , _left(nullptr)<br \/>\n        , _right(nullptr)<br \/>\n        , _parent(nullptr)<br \/>\n    {}<br \/>\n};<br \/>\ntemplate&lt;class K, class V&gt;<br \/>\nclass RBTree<br \/>\n{<br \/>\n    typedef RBTreeNode&lt;K, V&gt; Node;<br \/>\npublic:<br \/>\nprivate:<br \/>\n    Node* _root &#061; nullptr;<br \/>\n};<\/p>\n<p>\u7ed3\u6784\u4e0e\u4e4b\u524d\u7684AVL\u6811\u5927\u81f4\u76f8\u540c&#xff0c;\u4f46\u662f\u7ea2\u9ed1\u6811\u4e2d\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u7528\u6765\u8868\u793a\u989c\u8272\u7684Colour\u7ed3\u6784\u3002<\/p>\n<h3>2.\u63d2\u5165<\/h3>\n<h4>2.1.\u5927\u81f4\u8fc7\u7a0b<\/h4>\n<p>\u7ea2\u9ed1\u6811\u7684\u63d2\u5165\u5206\u4e3a\u4e24\u6b65&#xff1a;\u5148\u6309\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u89c4\u5219\u63d2\u5165\u8282\u70b9&#xff0c;\u518d\u68c0\u67e5\u5e76\u6062\u590d\u7ea2\u9ed1\u6811\u7684\u6027\u8d28\u3002<\/p>\n<p>&lt;1&gt;.\u6811\u4e3a\u7a7a&#xff1a;\u521b\u5efa\u65b0\u8282\u70b9\u4f5c\u4e3a\u6839\u8282\u70b9&#xff0c;\u5e76\u5c06\u5176\u8bbe\u4e3a\u9ed1\u8272&#xff0c;\u63d2\u5165\u7ed3\u675f\u3002<\/p>\n<p>&lt;2&gt;.\u6811\u4e0d\u4e3a\u7a7a&#xff1a;\u65b0\u589e\u8282\u70b9\u8bbe\u4e3a\u7ea2\u8272\u3002\u56e0\u4e3a\u63d2\u5165\u7ea2\u8272\u8282\u70b9\u4e0d\u4f1a\u6539\u53d8\u5404\u6761\u8def\u5f84\u4e0a\u7684\u9ed1\u8272\u8282\u70b9\u6570\u91cf&#xff1b;\u5982\u679c\u63d2\u5165\u9ed1\u8272\u8282\u70b9&#xff0c;\u5219\u4f1a\u7834\u574f\u9ed1\u8272\u8282\u70b9\u6570\u91cf\u76f8\u540c\u7684\u6027\u8d28&#xff0c;\u8c03\u6574\u8d77\u6765\u66f4\u52a0\u590d\u6742\u3002<\/p>\n<p>&lt;3&gt;.\u7236\u8282\u70b9\u4e3a\u9ed1\u8272&#xff1a;\u65b0\u589e\u7684\u7ea2\u8272\u8282\u70b9\u6ca1\u6709\u8fdd\u53cd\u4efb\u4f55\u6027\u8d28&#xff0c;\u63d2\u5165\u7ed3\u675f\u3002<\/p>\n<p>&lt;4&gt;.\u7236\u8282\u70b9\u4e3a\u7ea2\u8272&#xff1a;\u51fa\u73b0\u8fde\u7eed\u7684\u7ea2\u8272\u8282\u70b9&#xff0c;\u9700\u8981\u8fdb\u884c\u8c03\u6574\u3002\u6b64\u65f6&#xff0c;\u5f53\u524d\u8282\u70b9\u548c\u7236\u8282\u70b9\u90fd\u662f\u7ea2\u8272&#xff0c;\u7956\u7236\u8282\u70b9\u5fc5\u7136\u4e3a\u9ed1\u8272\u3002\u63a5\u4e0b\u6765\u9700\u8981\u6839\u636e\u53d4\u53d4\u8282\u70b9\u662f\u5426\u5b58\u5728\u53ca\u5176\u989c\u8272&#xff0c;\u7ed3\u5408\u5f53\u524d\u8282\u70b9\u4e0e\u7236\u8282\u70b9\u7684\u4f4d\u7f6e\u5173\u7cfb&#xff0c;\u5206\u522b\u5904\u7406\u3002<\/p>\n<p>\u540e\u7eed\u56fe\u4e2d\u7edf\u4e00\u4f7f\u7528\u4ee5\u4e0b\u6807\u8bb0&#xff1a;<\/p>\n<ul>\n<li>\n<p>c&#xff08;cur&#xff09;&#xff1a;\u5f53\u524d\u9700\u8981\u5904\u7406\u7684\u8282\u70b9&#xff0c;\u521d\u59cb\u4e3a\u65b0\u589e\u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>p&#xff08;parent&#xff09;&#xff1a;c \u7684\u7236\u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>g&#xff08;grandfather&#xff09;&#xff1a;p \u7684\u7236\u8282\u70b9&#xff0c;\u5373 c \u7684\u7956\u7236\u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>u&#xff08;uncle&#xff09;&#xff1a;p \u7684\u5144\u5f1f\u8282\u70b9&#xff0c;\u5373 c \u7684\u53d4\u53d4\u8282\u70b9\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8c03\u6574\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u9700\u8981\u7ee7\u7eed\u5411\u4e0a\u5904\u7406&#xff0c;\u56e0\u6b64 c \u4e0d\u4e00\u5b9a\u59cb\u7ec8\u6307\u5411\u6700\u521d\u65b0\u589e\u7684\u8282\u70b9\u3002<\/p>\n<h4>2.2.\u53d8\u8272<\/h4>\n<p>\u60c5\u51b5\u4e00&#xff1a;c \u4e3a\u7ea2\u8272&#xff0c;p \u4e3a\u7ea2\u8272&#xff0c;g \u4e3a\u9ed1\u8272&#xff0c;\u4e14\u53d4\u53d4\u8282\u70b9 u \u5b58\u5728\u5e76\u4e3a\u7ea2\u8272\u3002<\/p>\n<p>\u6b64\u65f6&#xff0c;c \u4e0e p \u8fde\u7eed\u4e3a\u7ea2\u8272&#xff0c;\u8fdd\u53cd\u4e86\u7ea2\u9ed1\u6811\u7684\u6027\u8d28\u3002\u5904\u7406\u65b9\u5f0f\u662f&#xff1a;<\/p>\n<p>\u5c06\u7236\u8282\u70b9 p \u548c\u53d4\u53d4\u8282\u70b9 u \u53d8\u4e3a\u9ed1\u8272\u3002<\/p>\n<p>\u5c06\u7956\u7236\u8282\u70b9 g \u53d8\u4e3a\u7ea2\u8272\u3002<\/p>\n<p>\u628a g \u5f53\u4f5c\u65b0\u7684 c&#xff0c;\u7ee7\u7eed\u5411\u4e0a\u68c0\u67e5\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u8fd9\u6837\u53d8\u8272&#xff1f;<\/p>\n<p>\u5c06 p \u548c u \u53d8\u9ed1\u540e&#xff0c;\u7ecf\u8fc7\u5b83\u4eec\u7684\u8def\u5f84\u90fd\u589e\u52a0\u4e86\u4e00\u4e2a\u9ed1\u8272\u8282\u70b9&#xff1b;\u518d\u5c06 g \u53d8\u7ea2&#xff0c;\u6bcf\u6761\u8def\u5f84\u53c8\u51cf\u5c11\u4e00\u4e2a\u9ed1\u8272\u8282\u70b9\u3002\u56e0\u6b64&#xff0c;\u4ece g \u6240\u5728\u5b50\u6811\u901a\u5f80\u5404\u4e2a NULL \u8282\u70b9\u7684\u8def\u5f84&#xff0c;\u9ed1\u8272\u8282\u70b9\u6570\u91cf\u4fdd\u6301\u4e0d\u53d8&#xff0c;\u540c\u65f6\u6d88\u9664\u4e86 c \u4e0e p \u8fde\u7eed\u4e3a\u7ea2\u8272\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u8fd8\u8981\u5411\u4e0a\u68c0\u67e5&#xff1f;<\/p>\n<p>\u56e0\u4e3a g \u53d8\u6210\u4e86\u7ea2\u8272&#xff0c;\u53ef\u80fd\u4e0e\u5b83\u7684\u7236\u8282\u70b9\u5f62\u6210\u65b0\u7684\u8fde\u7eed\u7ea2\u8272&#xff1a;<\/p>\n<ul>\n<li>\n<p>g \u7684\u7236\u8282\u70b9\u4e3a\u7ea2\u8272&#xff1a;\u7ee7\u7eed\u5411\u4e0a\u8c03\u6574\u3002<\/p>\n<\/li>\n<li>\n<p>g \u7684\u7236\u8282\u70b9\u4e3a\u9ed1\u8272&#xff1a;\u8c03\u6574\u7ed3\u675f\u3002<\/p>\n<\/li>\n<li>\n<p>g \u5df2\u7ecf\u662f\u6839\u8282\u70b9&#xff1a;\u5c06 g \u91cd\u65b0\u8bbe\u4e3a\u9ed1\u8272&#xff0c;\u8c03\u6574\u7ed3\u675f\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u60c5\u51b5\u53ea\u9700\u8981\u53d8\u8272&#xff0c;\u4e0d\u9700\u8981\u65cb\u8f6c\u3002 \u65e0\u8bba c \u662f p \u7684\u5de6\u5b69\u5b50\u8fd8\u662f\u53f3\u5b69\u5b50&#xff0c;p \u662f g \u7684\u5de6\u5b69\u5b50\u8fd8\u662f\u53f3\u5b69\u5b50&#xff0c;\u5904\u7406\u65b9\u5f0f\u90fd\u76f8\u540c\u3002<\/p>\n<p>\u53d8\u8272\u5982\u56fe&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1110\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124051-6ae5e1d3848f0.png\" width=\"2600\" \/><\/p>\n<p>\u8fd9\u4e2a\u56fe\u7247\u5411\u6211\u4eec\u5c55\u793a\u4e86\u2f00\u79cd\u5177\u4f53\u60c5\u51b5&#xff0c;\u4f46\u662f\u5b9e\u9645\u4e2d\u9700\u8981\u8fd9\u6837\u5904\u7406\u7684\u6709\u5f88\u591a\u79cd\u60c5\u51b5\u3002<\/p>\n<p>\u62bd\u8c61\u56fe\u5982\u4e0b&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1900\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124053-6ae5e1d5457a3.png\" width=\"3000\" \/><\/p>\n<p>\u8be5\u56fe\u5c06\u4ee5\u4e0a\u7c7b\u4f3c\u7684\u5904\u7406\u8fdb\u884c\u4e86\u62bd\u8c61\u8868\u8fbe&#xff0c;d\/e\/f\u4ee3\u8868\u6bcf\u6761\u8def\u5f84\u62e5\u6709hb\u4e2a\u9ed1\u8272\u7ed3\u70b9\u7684\u5b50\u6811&#xff0c;a\/b\u4ee3\u8868\u6bcf <\/p>\n<p>\u6761\u8def\u5f84\u62e5\u6709hb-1\u4e2a\u9ed1\u8272\u7ed3\u70b9\u7684\u6839\u4e3a\u7ea2\u7684\u5b50\u6811&#xff0c;hb&gt;&#061;0\u3002<\/p>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>bool Insert(const pair&lt;K, V&gt;&amp; kv)<br \/>\n{<br \/>\nif (_root &#061;&#061; nullptr)<br \/>\n{<br \/>\n_root &#061; new Node(kv);<br \/>\n_root-&gt;_col &#061; Black;<br \/>\nreturn true;<br \/>\n}<\/p>\n<p>\/\/\u5bfb\u627e\u63d2\u5165\u7684\u5730\u65b9<br \/>\nNode* parent &#061; nullptr;<br \/>\nNode* cur &#061; _root;<br \/>\nwhile (cur)<br \/>\n{<br \/>\nif (cur-&gt;_kv.first &lt; kv.first)<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\ncur &#061; cur-&gt;_right;<br \/>\n}<br \/>\nelse if (cur-&gt;_kv.first &gt; kv.first)<br \/>\n{<br \/>\nparent &#061; cur;<br \/>\ncur &#061; cur-&gt;_left;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nreturn false;<br \/>\n}<br \/>\n}<br \/>\n\/\/\u63d2\u5165\u8282\u70b9<br \/>\ncur &#061; new Node(kv);<br \/>\ncur-&gt;_col &#061; Red;<br \/>\nif (parent-&gt;_kv.first &lt; kv.first)<br \/>\n{<br \/>\nparent-&gt;_right &#061; cur;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nparent-&gt;_left &#061; cur;<br \/>\n}<br \/>\ncur-&gt;_parent &#061; parent;<\/p>\n<p>\/\/\u68c0\u67e5parent\u662f\u5426\u4e3aRed<br \/>\n\/\/\u6ce8\u610f\u6b64\u5904\u662f\u5148\u68c0\u67e5parent\u662f\u5426\u5b58\u5728&#xff0c;\u5728\u68c0\u67e5parent\u7684\u989c\u8272\u662f\u5426\u4e3a\u7ea2\u8272<br \/>\nwhile (parent&amp;&amp;parent-&gt;_col &#061;&#061; Red)<br \/>\n{<br \/>\nNode* grandfather &#061; parent-&gt;_parent;<br \/>\nif (grandfather-&gt;_left &#061;&#061; parent)<br \/>\n{<br \/>\nNode* uncle &#061; grandfather-&gt;_right;<br \/>\n\/\/\u67d3\u8272\u4e0d\u65cb\u8f6c<br \/>\nif (uncle &amp;&amp; uncle-&gt;_col &#061;&#061; Red)<br \/>\n{<br \/>\nparent-&gt;_col &#061; Black;<br \/>\nuncle-&gt;_col &#061; Black;<br \/>\ngrandfather-&gt;_col &#061; Red;<br \/>\n\/\/ \u7ee7\u7eed\u5f80\u4e0a\u5904\u7406<br \/>\ncur &#061; grandfather;<br \/>\nparent &#061; cur-&gt;_parent;<br \/>\n}<br \/>\n\/\/uncle-&gt;_col &#061;&#061; Black||uncle&#061;&#061;nullptr<br \/>\nelse<br \/>\n{<br \/>\n            }<br \/>\n}<br \/>\n\/\/grandfather-&gt;_right &#061;&#061; parent<br \/>\nelse<br \/>\n{<br \/>\nNode* uncle &#061; grandfather-&gt;_left;<br \/>\nif (uncle &amp;&amp; uncle-&gt;_col &#061;&#061; Red)<br \/>\n{<br \/>\nparent-&gt;_col &#061; Black;<br \/>\nuncle-&gt;_col &#061; Black;<br \/>\ngrandfather-&gt;_col &#061; Red;<\/p>\n<p>cur &#061; grandfather;<br \/>\nparent &#061; cur-&gt;_parent;<br \/>\n}<\/p>\n<p>else<br \/>\n{<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\nreturn true;<br \/>\n}<\/p>\n<p>\u4f46\u662f&#xff0c;\u6211\u4eec\u8fd8\u6709\u4e2a\u95ee\u9898&#xff1a;\u4f1a\u4e0d\u4f1a\u6539\u7740\u6539\u7740\u5c06\u6839\u8282\u70b9\u7ed9\u6539\u6210\u7ea2\u8272\u7684\u4e86&#xff1f;\u5f53\u7136\u662f\u6709\u8fd9\u79cd\u53ef\u80fd\u7684&#xff0c;\u6240\u4ee5\u6211\u4eec\u8981\u5728\u6700\u540e\u52a0\u4e0a&#xff1a;<\/p>\n<p>_root-&gt;_col &#061; Black;<\/p>\n<p>\u800c\u4e14\u6211\u4eec\u8fd9\u4e2a\u4ee3\u7801\u8fd8\u8981\u533a\u5206grandfather\u7684\u5de6\u8282\u70b9\u548c\u53f3\u8282\u70b9\u54ea\u4e00\u4e2a\u6307\u5411parent?\u8fd9\u4e2a\u5c06\u4f1a\u5f71\u54cd\u540e\u9762<\/p>\n<p>\u7684\u65cb\u8f6c&#xff0c;\u4f46\u662f\u8fd9\u7bc7\u6587\u7ae0\u6211\u4eec\u4f18\u5148\u8003\u8651grandfather-&gt;_left&#061;&#061;parent&#xff0c;\u5f53\u6211\u4eec\u771f\u6b63\u7684\u4e86\u89e3\u601d\u60f3\u540e\u5c31\u53ef\u4ee5\u72ec\u7acb\u7684\u5199grandfather-&gt;_right&#061;&#061;parent\u7684\u4ee3\u7801\u4e86\u3002<\/p>\n<h4 style=\"background-color:transparent\">2.3.\u5355\u65cb&#043;\u53d8\u8272<\/h4>\n<p>\u60c5\u51b5\u4e8c&#xff1a;c \u4e3a\u7ea2\u8272&#xff0c;p \u4e3a\u7ea2\u8272&#xff0c;g \u4e3a\u9ed1\u8272&#xff0c;\u53d4\u53d4\u8282\u70b9 u \u4e0d\u5b58\u5728\u6216\u4e3a\u9ed1\u8272\u3002<\/p>\n<p>\u8fd9\u91cc\u53ef\u4ee5\u8fdb\u4e00\u6b65\u533a\u5206&#xff1a;<\/p>\n<ul>\n<li>\n<p>u \u4e0d\u5b58\u5728&#xff1a;c \u662f\u672c\u6b21\u65b0\u589e\u7684\u7ea2\u8272\u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>u \u5b58\u5728\u4e14\u4e3a\u9ed1\u8272&#xff1a;c \u4e0d\u662f\u65b0\u589e\u8282\u70b9&#xff0c;\u800c\u662f\u5728\u4e0b\u5c42\u6309\u60c5\u51b5\u4e00\u8c03\u6574\u65f6&#xff0c;\u7531\u9ed1\u8272\u53d8\u4e3a\u7ea2\u8272&#xff0c;\u518d\u4f5c\u4e3a\u65b0\u7684 c \u5411\u4e0a\u4f20\u9012\u7684\u8282\u70b9\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6b64\u65f6&#xff0c;c \u4e0e p \u8fde\u7eed\u4e3a\u7ea2\u8272&#xff0c;\u9700\u8981\u8c03\u6574\u3002\u4f46\u7531\u4e8e\u53d4\u53d4\u4e00\u4fa7\u6ca1\u6709\u7ea2\u8272\u8282\u70b9\u53ef\u4ee5\u4e00\u8d77\u53d8\u9ed1&#xff0c;\u5355\u7eaf\u53d8\u8272\u65e0\u6cd5\u540c\u65f6\u4fdd\u8bc1\u9ed1\u8272\u8282\u70b9\u6570\u91cf\u76f8\u540c&#xff0c;\u56e0\u6b64\u9700\u8981\u901a\u8fc7\u65cb\u8f6c\u914d\u5408\u53d8\u8272\u6062\u590d\u7ea2\u9ed1\u6811\u7684\u6027\u8d28\u3002<\/p>\n<p>&lt;1&gt;. p \u662f g \u7684\u5de6\u5b69\u5b50&#xff0c;c \u662f p \u7684\u5de6\u5b69\u5b50&#xff1a;\u53f3\u5355\u65cb&#xff0b;\u53d8\u8272<\/p>\n<p>     g<br \/>\n  p     u(\u53ef\u80fd\u4e0d\u5b58\u5728)<br \/>\nc<\/p>\n<p>\u6b64\u65f6&#xff0c;g\u3001p\u3001c \u5f62\u6210\u5de6\u5de6\u7ed3\u6784&#xff0c;\u5904\u7406\u6b65\u9aa4\u5982\u4e0b&#xff1a;<\/p>\n<li>\n<p>\u4ee5 g \u4e3a\u65cb\u8f6c\u70b9\u8fdb\u884c\u53f3\u5355\u65cb&#xff0c;\u8ba9 p \u6210\u4e3a\u8fd9\u68f5\u5b50\u6811\u7684\u65b0\u6839\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c06 p \u53d8\u4e3a\u9ed1\u8272&#xff0c;g \u53d8\u4e3a\u7ea2\u8272\u3002<\/p>\n<\/li>\n<li>\n<p>c \u4fdd\u6301\u7ea2\u8272\u3002<\/p>\n<\/li>\n<p>\u8c03\u6574\u540e&#xff0c;p \u4e3a\u9ed1\u8272&#xff0c;c \u548c g \u4e3a\u7ea2\u8272&#xff0c;\u6d88\u9664\u4e86\u8fde\u7eed\u7ea2\u8272\u8282\u70b9&#xff0c;\u540c\u65f6\u4fdd\u6301\u8fd9\u68f5\u5b50\u6811\u5404\u6761\u8def\u5f84\u4e0a\u7684\u9ed1\u8272\u8282\u70b9\u6570\u91cf\u4e0d\u53d8\u3002<\/p>\n<p>&lt;2&gt;. p \u662f g \u7684\u53f3\u5b69\u5b50&#xff0c;c \u662f p \u7684\u53f3\u5b69\u5b50&#xff1a;\u5de6\u5355\u65cb&#xff0b;\u53d8\u8272<\/p>\n<p>    g<br \/>\n u     p<br \/>\n         c<\/p>\n<p>\u6b64\u65f6&#xff0c;g\u3001p\u3001c \u5f62\u6210\u53f3\u53f3\u7ed3\u6784&#xff0c;\u4e0e\u5de6\u5de6\u60c5\u51b5\u5bf9\u79f0&#xff1a;<\/p>\n<li>\n<p>\u4ee5 g \u4e3a\u65cb\u8f6c\u70b9\u8fdb\u884c\u5de6\u5355\u65cb&#xff0c;\u8ba9 p \u6210\u4e3a\u8fd9\u68f5\u5b50\u6811\u7684\u65b0\u6839\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c06 p \u53d8\u4e3a\u9ed1\u8272&#xff0c;g \u53d8\u4e3a\u7ea2\u8272\u3002<\/p>\n<\/li>\n<li>\n<p>c \u4fdd\u6301\u7ea2\u8272\u3002<\/p>\n<\/li>\n<p>\u8c03\u6574\u540e&#xff0c;\u540c\u6837\u6d88\u9664\u4e86\u8fde\u7eed\u7ea2\u8272\u8282\u70b9&#xff0c;\u5e76\u4fdd\u6301\u8fd9\u68f5\u5b50\u6811\u5404\u6761\u8def\u5f84\u4e0a\u7684\u9ed1\u8272\u8282\u70b9\u6570\u91cf\u4e0d\u53d8\u3002<\/p>\n<p>\u8fd9\u4e24\u79cd\u60c5\u51b5\u8c03\u6574\u5b8c\u6210\u540e&#xff0c;\u90fd\u4e0d\u9700\u8981\u7ee7\u7eed\u5411\u4e0a\u5904\u7406\u3002<\/p>\n<p>\u56e0\u4e3a\u65b0\u7684\u5b50\u6811\u6839\u8282\u70b9 p \u4e3a\u9ed1\u8272&#xff0c;\u65e0\u8bba\u5b83\u4e0a\u9762\u8fde\u63a5\u7684\u662f\u7ea2\u8272\u8282\u70b9\u3001\u9ed1\u8272\u8282\u70b9&#xff0c;\u8fd8\u662f\u5b83\u76f4\u63a5\u6210\u4e3a\u6574\u68f5\u6811\u7684\u6839&#xff0c;\u90fd\u4e0d\u4f1a\u4ea7\u751f\u65b0\u7684\u989c\u8272\u51b2\u7a81&#xff1b;\u540c\u65f6&#xff0c;\u5b50\u6811\u5bf9\u5916\u7684\u9ed1\u8272\u9ad8\u5ea6\u4fdd\u6301\u4e0d\u53d8&#xff0c;\u4e0d\u4f1a\u5f71\u54cd\u5176\u4ed6\u8def\u5f84\u3002<\/p>\n<p>\u8fd9\u91cc\u6211\u62ff\u4e0a\u9762\u7684\u53f3\u5355\u65cb\u6765\u4e3e\u4f8b\u5b50&#xff1a;<\/p>\n<p>\u793a\u4f8b\u4e00:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"670\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124056-6ae5e1d81b362.png\" width=\"2100\" \/><\/p>\n<p>\u63d2\u5165\u7ea2\u8272\u8282\u70b9 3 \u540e&#xff0c;3 \u4e0e\u7236\u8282\u70b9 6 \u8fde\u7eed\u4e3a\u7ea2&#xff0c;\u5f62\u6210\u5de6\u5de6\u7ed3\u6784\u3002\u4ee5 10 \u4e3a\u65cb\u8f6c\u70b9\u53f3\u5355\u65cb&#xff0c;\u518d\u5c06 6 \u53d8\u9ed1\u300110 \u53d8\u7ea2&#xff0c;\u8c03\u6574\u7ed3\u675f\u3002<\/p>\n<p>\u793a\u4f8b\u4e8c&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1060\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124056-6ae5e1d8bacb7.png\" width=\"3050\" \/><\/p>\n<p>\u8282\u70b9 3 \u539f\u672c\u4e3a\u9ed1\u8272\u3002\u5728\u5b83\u7684\u5b50\u6811\u4e2d\u63d2\u5165\u8282\u70b9\u5e76\u8fdb\u884c\u53d8\u8272\u540e&#xff0c;3 \u53d8\u7ea2&#xff0c;\u4f5c\u4e3a\u65b0\u7684 c \u5411\u4e0a\u68c0\u67e5&#xff0c;\u4e0e\u7ea2\u8272\u7236\u8282\u70b9 6 \u4ea7\u751f\u51b2\u7a81\u3002<\/p>\n<p>\u6b64\u65f6\u53d4\u53d4 15 \u4e3a\u9ed1\u8272&#xff0c;\u9700\u8981\u4ee5 10 \u4e3a\u65cb\u8f6c\u70b9\u53f3\u5355\u65cb&#xff1a;<\/p>\n<ul>\n<li>6 \u6210\u4e3a\u8fd9\u68f5\u5b50\u6811\u7684\u65b0\u6839\u3002<\/li>\n<li>\u5b50\u6811 d \u4ece 6 \u7684\u53f3\u5b50\u6811&#xff0c;\u8f6c\u63a5\u4e3a 10 \u7684\u5de6\u5b50\u6811\u3002<\/li>\n<li>10 \u6210\u4e3a 6 \u7684\u53f3\u5b69\u5b50\u3002<\/li>\n<li>\u5c06 6 \u53d8\u9ed1\u300110 \u53d8\u7ea2&#xff0c;3 \u4fdd\u6301\u7ea2\u8272\u3002<\/li>\n<\/ul>\n<p>\u793a\u4f8b\u4e09&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1160\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124058-6ae5e1da2ec46.png\" width=\"3050\" \/><\/p>\n<p>\u6700\u521d a\u3001b \u7684\u6839\u4e3a\u7ea2\u8272&#xff0c;d \u7684\u6839\u4e3a\u9ed1\u8272\u3002\u4e0b\u5c42\u63d2\u5165\u5e76\u53d8\u8272\u540e&#xff0c;a\u3001b \u7684\u6839\u53d8\u9ed1&#xff0c;\u8282\u70b9 3 \u53d8\u7ea2&#xff0c;\u56e0\u6b64\u7ecf\u8fc7 3 \u7684\u8def\u5f84\u4e0a&#xff0c;\u9ed1\u8272\u8282\u70b9\u6570\u91cf\u4fdd\u6301\u4e0d\u53d8\u3002<\/p>\n<p>\u968f\u540e\u8fdb\u884c\u53f3\u5355\u65cb\u548c\u53d8\u8272&#xff0c;\u6d88\u9664 3 \u4e0e 6 \u8fde\u7eed\u4e3a\u7ea2\u7684\u95ee\u9898\u3002\u8c03\u6574\u540e\u7684\u5b50\u6811\u6839 6 \u4e3a\u9ed1\u8272&#xff0c;\u5b50\u6811\u5bf9\u5916\u7684\u9ed1\u8272\u9ad8\u5ea6\u4fdd\u6301\u4e0d\u53d8&#xff0c;\u4e0d\u9700\u8981\u7ee7\u7eed\u5411\u4e0a\u8c03\u6574\u3002<\/p>\n<p>\u4ee3\u7801&#xff1a;<\/p>\n<p>\/\/\u5b58\u5728\u4e14\u4e3a\u2fca\u6216\u4e0d\u5b58\u5728-\u300b\u65cb\u8f6c&#043;\u53d8\u2f8a<br \/>\nif (parent-&gt;_left &#061;&#061; cur)<br \/>\n{<br \/>\n    Rotate_Right(grandfather);<br \/>\nparent-&gt;_col &#061; Black;<br \/>\ngrandfather-&gt;_col &#061; Red;<br \/>\n}<\/p>\n<h4 style=\"background-color:transparent\">2.4.\u53cc\u65cb&#043;\u53d8\u8272<\/h4>\n<p>\u60c5\u51b5\u4e09&#xff1a;c \u4e3a\u7ea2\u8272&#xff0c;p \u4e3a\u7ea2\u8272&#xff0c;g \u4e3a\u9ed1\u8272&#xff0c;\u53d4\u53d4\u8282\u70b9 u \u4e0d\u5b58\u5728\u6216\u4e3a\u9ed1\u8272&#xff0c;\u4e14 c \u4e0e p \u7684\u65b9\u5411\u4e0d\u540c\u3002<\/p>\n<p>\u5176\u4e2d&#xff1a;<\/p>\n<ul>\n<li>\n<p>u \u4e0d\u5b58\u5728&#xff1a;c \u662f\u672c\u6b21\u65b0\u589e\u7684\u7ea2\u8272\u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>u \u5b58\u5728\u4e14\u4e3a\u9ed1\u8272&#xff1a;c \u662f\u4e0b\u5c42\u6309\u60c5\u51b5\u4e00\u53d8\u8272\u540e&#xff0c;\u7531\u9ed1\u8272\u53d8\u4e3a\u7ea2\u8272&#xff0c;\u518d\u5411\u4e0a\u4f20\u9012\u7684\u8282\u70b9\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6b64\u65f6&#xff0c;c \u4e0e p \u8fde\u7eed\u4e3a\u7ea2\u8272&#xff0c;\u5355\u7eaf\u53d8\u8272\u65e0\u6cd5\u540c\u65f6\u7ef4\u6301\u5404\u6761\u8def\u5f84\u4e0a\u7684\u9ed1\u8272\u8282\u70b9\u6570\u91cf&#xff0c;\u9700\u8981\u901a\u8fc7\u53cc\u65cb\u914d\u5408\u53d8\u8272\u6062\u590d\u7ea2\u9ed1\u6811\u7684\u6027\u8d28\u3002<\/p>\n<p>&lt;1&gt;. p \u662f g \u7684\u5de6\u5b69\u5b50&#xff0c;c \u662f p \u7684\u53f3\u5b69\u5b50&#xff1a;\u5de6\u53f3\u53cc\u65cb&#xff0b;\u53d8\u8272<\/p>\n<p>     g<br \/>\n  p     u(\u53ef\u80fd\u4e0d\u5b58\u5728)<br \/>\n    c<\/p>\n<p>\u5904\u7406\u6b65\u9aa4\u5982\u4e0b&#xff1a;<\/p>\n<li>\n<p>\u4ee5 p \u4e3a\u65cb\u8f6c\u70b9\u8fdb\u884c\u5de6\u5355\u65cb&#xff0c;\u5c06\u5de6\u53f3\u7ed3\u6784\u8f6c\u5316\u4e3a\u5de6\u5de6\u7ed3\u6784\u3002<\/p>\n<\/li>\n<li>\n<p>\u4ee5 g \u4e3a\u65cb\u8f6c\u70b9\u8fdb\u884c\u53f3\u5355\u65cb&#xff0c;\u8ba9\u539f\u6765\u7684 c \u6210\u4e3a\u8fd9\u68f5\u5b50\u6811\u7684\u65b0\u6839\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c06 c \u53d8\u4e3a\u9ed1\u8272&#xff0c;g \u53d8\u4e3a\u7ea2\u8272&#xff0c;p \u4fdd\u6301\u7ea2\u8272\u3002<\/p>\n<\/li>\n<p>\u8c03\u6574\u540e&#xff0c;c \u4e3a\u9ed1\u8272&#xff0c;\u5de6\u53f3\u5b69\u5b50 p\u3001g \u4e3a\u7ea2\u8272&#xff0c;\u6d88\u9664\u4e86\u8fde\u7eed\u7ea2\u8272\u8282\u70b9&#xff0c;\u5e76\u4fdd\u6301\u5b50\u6811\u5404\u6761\u8def\u5f84\u4e0a\u7684\u9ed1\u8272\u8282\u70b9\u6570\u91cf\u4e0d\u53d8\u3002<\/p>\n<p>&lt;2&gt;. p \u662f g \u7684\u53f3\u5b69\u5b50&#xff0c;c \u662f p \u7684\u5de6\u5b69\u5b50&#xff1a;\u53f3\u5de6\u53cc\u65cb&#xff0b;\u53d8\u8272<\/p>\n<p>    g<br \/>\n u     p<br \/>\n     c<\/p>\n<p>\u5904\u7406\u6b65\u9aa4\u4e0e\u5de6\u53f3\u60c5\u51b5\u5bf9\u79f0&#xff1a;<\/p>\n<li>\n<p>\u4ee5 p \u4e3a\u65cb\u8f6c\u70b9\u8fdb\u884c\u53f3\u5355\u65cb&#xff0c;\u5c06\u53f3\u5de6\u7ed3\u6784\u8f6c\u5316\u4e3a\u53f3\u53f3\u7ed3\u6784\u3002<\/p>\n<\/li>\n<li>\n<p>\u4ee5 g \u4e3a\u65cb\u8f6c\u70b9\u8fdb\u884c\u5de6\u5355\u65cb&#xff0c;\u8ba9\u539f\u6765\u7684 c \u6210\u4e3a\u8fd9\u68f5\u5b50\u6811\u7684\u65b0\u6839\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c06 c \u53d8\u4e3a\u9ed1\u8272&#xff0c;g \u53d8\u4e3a\u7ea2\u8272&#xff0c;p \u4fdd\u6301\u7ea2\u8272\u3002<\/p>\n<\/li>\n<p>\u53cc\u65cb\u5b8c\u6210\u540e&#xff0c;\u53d8\u9ed1\u7684\u662f\u65b0\u7684\u5b50\u6811\u6839 c&#xff0c;\u800c\u4e0d\u662f p\u3002<\/p>\n<p>\u65b0\u7684\u5b50\u6811\u6839 c \u4e3a\u9ed1\u8272&#xff0c;\u65e0\u8bba\u5b83\u4e0a\u9762\u8fde\u63a5\u7684\u662f\u7ea2\u8272\u8282\u70b9\u3001\u9ed1\u8272\u8282\u70b9&#xff0c;\u8fd8\u662f\u5b83\u76f4\u63a5\u6210\u4e3a\u6574\u68f5\u6811\u7684\u6839&#xff0c;\u90fd\u4e0d\u4f1a\u4ea7\u751f\u65b0\u7684\u989c\u8272\u51b2\u7a81\u3002\u540c\u65f6&#xff0c;\u5b50\u6811\u5bf9\u5916\u7684\u9ed1\u8272\u9ad8\u5ea6\u4fdd\u6301\u4e0d\u53d8&#xff0c;\u56e0\u6b64\u4e0d\u9700\u8981\u7ee7\u7eed\u5411\u4e0a\u8c03\u6574\u3002<\/p>\n<p>\u90a3\u4e48\u6211\u62ff\u4e0a\u9762\u7684\u5de6\u53f3\u5355\u65cb\u6765\u4e3e\u4f8b\u5b50&#xff1a;<\/p>\n<p>\u793a\u4f8b\u4e00&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"840\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124059-6ae5e1dbbe408.png\" width=\"4200\" \/><\/p>\n<\/p>\n<p>\u5148\u4ee5 p&#xff08;6&#xff09; \u5de6\u65cb&#xff0c;\u4f7f 8 \u6210\u4e3a 10 \u7684\u5de6\u5b69\u5b50&#xff0c;6 \u6210\u4e3a 8 \u7684\u5de6\u5b69\u5b50&#xff1b;\u518d\u4ee5 g&#xff08;10&#xff09; \u53f3\u65cb&#xff0c;\u4f7f 8 \u6210\u4e3a\u5b50\u6811\u7684\u65b0\u6839\u3002\u6700\u540e\u5c06 8 \u53d8\u9ed1\u300110 \u53d8\u7ea2&#xff0c;6 \u4fdd\u6301\u7ea2\u8272\u3002<\/p>\n<p>\u793a\u4f8b\u4e8c&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1130\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124100-6ae5e1dce8260.png\" width=\"4200\" \/><\/p>\n<p>\u7b2c\u4e00\u6b21\u5de6\u65cb\u65f6&#xff0c;\u5b50\u6811 a \u8f6c\u63a5\u4e3a 6 \u7684\u53f3\u5b50\u6811&#xff0c;b \u4ecd\u4e3a 8 \u7684\u53f3\u5b50\u6811\u3002\u7b2c\u4e8c\u6b21\u53f3\u65cb\u65f6&#xff0c;\u5b50\u6811 b \u8f6c\u63a5\u4e3a 10 \u7684\u5de6\u5b50\u6811\u3002\u6700\u7ec8 6\u300110 \u5206\u522b\u6210\u4e3a 8 \u7684\u5de6\u53f3\u5b69\u5b50\u3002<\/p>\n<p>\u793a\u4f8b\u4e09&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1240\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124102-6ae5e1dec6b6c.png\" width=\"4200\" \/><\/p>\n<p>\u4e0b\u5c42\u63d2\u5165\u5e76\u53d8\u8272\u540e&#xff0c;8 \u7531\u9ed1\u53d8\u7ea2&#xff0c;\u4e0e\u7236\u8282\u70b9 6 \u4ea7\u751f\u51b2\u7a81\u3002\u968f\u540e\u4f9d\u6b21\u5de6\u65cb\u3001\u53f3\u65cb\u5e76\u53d8\u8272&#xff0c;\u5728\u6d88\u9664\u8fde\u7eed\u7ea2\u8272\u8282\u70b9\u7684\u540c\u65f6&#xff0c;\u4fdd\u6301\u5b50\u6811\u5bf9\u5916\u7684\u9ed1\u8272\u9ad8\u5ea6\u4e0d\u53d8&#xff0c;\u8c03\u6574\u7ed3\u675f\u3002<\/p>\n<p>\u4ee3\u7801&#xff1a;<\/p>\n<p>\/\/\u67d3\u8272&#043;\u53cc\u65cb\u8f6c,parent-&gt;_right &#061;&#061; cur<br \/>\nelse<br \/>\n{<br \/>\nRotate_Left(parent);<br \/>\nRotate_Right(grandfather);<br \/>\ncur-&gt;_col &#061; Black;<br \/>\ngrandfather-&gt;_col &#061; Red;<br \/>\n}<br \/>\nbreak;<\/p>\n<p>\u6240\u4ee5\u4e00\u4e2a\u534a\u5b8c\u6574\u7684\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>if (grandfather-&gt;_left &#061;&#061; parent)<br \/>\n{<br \/>\nNode* uncle &#061; grandfather-&gt;_right;<br \/>\n\/\/\u67d3\u8272\u4e0d\u65cb\u8f6c<br \/>\nif (uncle &amp;&amp; uncle-&gt;_col &#061;&#061; Red)<br \/>\n{<br \/>\nparent-&gt;_col &#061; Black;<br \/>\nuncle-&gt;_col &#061; Black;<br \/>\ngrandfather-&gt;_col &#061; Red;<br \/>\n\/\/ \u7ee7\u7eed\u5f80\u4e0a\u5904\u7406<br \/>\ncur &#061; grandfather;<br \/>\nparent &#061; cur-&gt;_parent;<br \/>\n}<br \/>\n\/\/uncle-&gt;_col &#061;&#061; Black||uncle&#061;&#061;nullptr<br \/>\nelse<br \/>\n{<br \/>\n\/\/\u5b58\u5728\u4e14\u4e3a\u2fca\u6216\u4e0d\u5b58\u5728-\u300b\u65cb\u8f6c&#043;\u53d8\u2f8a<br \/>\nif (parent-&gt;_left &#061;&#061; cur)<br \/>\n{<br \/>\nRotate_Right(grandfather);<br \/>\nparent-&gt;_col &#061; Black;<br \/>\ngrandfather-&gt;_col &#061; Red;<br \/>\n}<br \/>\n\/\/\u67d3\u8272&#043;\u53cc\u65cb\u8f6c,parent-&gt;_right &#061;&#061; cur<br \/>\nelse<br \/>\n{<br \/>\nRotate_Left(parent);<br \/>\nRotate_Right(grandfather);<br \/>\ncur-&gt;_col &#061; Black;<br \/>\ngrandfather-&gt;_col &#061; Red;<br \/>\n}<br \/>\nbreak;<br \/>\n}<br \/>\n}<\/p>\n<p>\u90a3\u4e48\u8fd9\u4e2agrandfather-&gt;_right &#061;&#061; parent\u7684\u4ee3\u7801\u6211\u5c31\u4e0d\u518d\u8be6\u7ec6\u7684\u89e3\u91ca\u4e86&#xff0c;\u5982\u4e0b&#xff1a;<\/p>\n<p>\/\/ grandfather-&gt;_right &#061;&#061; parent<br \/>\nelse<br \/>\n{<br \/>\n    Node* uncle &#061; grandfather-&gt;_left;<\/p>\n<p>    \/\/ \u67d3\u8272&#xff0c;\u4e0d\u65cb\u8f6c<br \/>\n    if (uncle &amp;&amp; uncle-&gt;_col &#061;&#061; Red)<br \/>\n    {<br \/>\n        parent-&gt;_col &#061; Black;<br \/>\n        uncle-&gt;_col &#061; Black;<br \/>\n        grandfather-&gt;_col &#061; Red;<\/p>\n<p>        cur &#061; grandfather;<br \/>\n        parent &#061; cur-&gt;_parent;<br \/>\n    }<br \/>\n    else<br \/>\n    {<br \/>\n        \/\/ \u67d3\u8272 &#043; \u5355\u65cb\u8f6c<br \/>\n        if (parent-&gt;_right &#061;&#061; cur)<br \/>\n        {<br \/>\n            Rotate_Left(grandfather);<\/p>\n<p>            parent-&gt;_col &#061; Black;<br \/>\n            grandfather-&gt;_col &#061; Red;<br \/>\n        }<br \/>\n        \/\/ \u67d3\u8272 &#043; \u53cc\u65cb\u8f6c&#xff0c;parent-&gt;_left &#061;&#061; cur<br \/>\n        else<br \/>\n        {<br \/>\n            Rotate_Right(parent);<br \/>\n            Rotate_Left(grandfather);<\/p>\n<p>            cur-&gt;_col &#061; Black;<br \/>\n            grandfather-&gt;_col &#061; Red;<br \/>\n        }<\/p>\n<p>        break;<br \/>\n    }<br \/>\n}<\/p>\n<h3 style=\"background-color:transparent\">3.\u9a8c\u8bc1<\/h3>\n<p>\u4ec5\u901a\u8fc7\u83b7\u53d6\u6700\u957f\u8def\u5f84\u548c\u6700\u77ed\u8def\u5f84&#xff0c;\u68c0\u67e5\u6700\u957f\u8def\u5f84\u662f\u5426\u4e0d\u8d85\u8fc7\u6700\u77ed\u8def\u5f84\u7684 2 \u500d&#xff0c;\u65e0\u6cd5\u5224\u65ad\u4e00\u68f5\u6811\u662f\u5426\u6ee1\u8db3\u7ea2\u9ed1\u6811\u7684\u89c4\u5219\u3002<\/p>\n<p>\u56e0\u4e3a\u5373\u4f7f\u6ee1\u8db3\u8fd9\u4e2a\u6761\u4ef6&#xff0c;\u7ed3\u70b9\u7684\u989c\u8272\u4ecd\u53ef\u80fd\u8fdd\u53cd\u89c4\u5219\u3002\u5f53\u524d\u6682\u65f6\u6ca1\u6709\u51fa\u73b0\u95ee\u9898&#xff0c;\u540e\u7eed\u7ee7\u7eed\u63d2\u5165\u65f6\u4e5f\u53ef\u80fd\u51fa\u73b0\u95ee\u9898\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u6211\u4eec\u8fd8\u662f\u9700\u8981\u68c0\u67e5\u4ee5\u4e0b 4 \u6761\u89c4\u5219\u3002\u6ee1\u8db3\u8fd9\u4e9b\u89c4\u5219&#xff0c;\u5c31\u80fd\u4fdd\u8bc1\u6700\u957f\u8def\u5f84\u4e0d\u8d85\u8fc7\u6700\u77ed\u8def\u5f84\u7684 2 \u500d\u3002<\/p>\n<p>&lt;1&gt;.\u7ed3\u70b9\u7684\u989c\u8272\u4e0d\u662f\u9ed1\u8272&#xff0c;\u5c31\u662f\u7ea2\u8272\u3002<\/p>\n<p>\u4f7f\u7528\u679a\u4e3e\u7c7b\u578b\u5b9a\u4e49\u989c\u8272&#xff0c;\u5728\u6b63\u5e38\u4f7f\u7528\u7684\u60c5\u51b5\u4e0b\u5373\u53ef\u4fdd\u8bc1\u8fd9\u4e00\u70b9\u3002<\/p>\n<p>&lt;2&gt;.\u6839\u7ed3\u70b9\u5fc5\u987b\u662f\u9ed1\u8272\u3002<\/p>\n<p>\u76f4\u63a5\u68c0\u67e5\u6839\u7ed3\u70b9\u7684\u989c\u8272\u5373\u53ef\u3002<\/p>\n<p>&lt;3&gt;.\u4e0d\u80fd\u51fa\u73b0\u8fde\u7eed\u7684\u7ea2\u8272\u7ed3\u70b9\u3002<\/p>\n<p>\u4f7f\u7528\u524d\u5e8f\u904d\u5386\u68c0\u67e5\u3002\u9047\u5230\u7ea2\u8272\u7ed3\u70b9\u65f6&#xff0c;\u53ef\u4ee5\u68c0\u67e5\u5176\u5b69\u5b50\u662f\u5426\u4e3a\u7ea2\u8272&#xff0c;\u4f46\u5b69\u5b50\u6709\u4e24\u4e2a&#xff0c;\u800c\u4e14\u4e0d\u4e00\u5b9a\u5b58\u5728\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u53cd\u8fc7\u6765\u68c0\u67e5\u5176\u7236\u4eb2\u7684\u989c\u8272\u66f4\u65b9\u4fbf&#xff1a;\u5982\u679c\u5f53\u524d\u7ed3\u70b9\u548c\u7236\u4eb2\u90fd\u662f\u7ea2\u8272&#xff0c;\u5c31\u8fdd\u53cd\u4e86\u89c4\u5219\u3002<\/p>\n<p>&lt;4&gt;.\u4ece\u6839\u7ed3\u70b9\u5230\u6bcf\u4e2a\u7a7a\u7ed3\u70b9\u7684\u8def\u5f84\u4e0a&#xff0c;\u9ed1\u8272\u7ed3\u70b9\u7684\u6570\u91cf\u5fc5\u987b\u76f8\u540c\u3002<\/p>\n<p>\u4f7f\u7528\u524d\u5e8f\u904d\u5386&#xff0c;\u901a\u8fc7\u5f62\u53c2 blackNum \u8bb0\u5f55\u4ece\u6839\u7ed3\u70b9\u5230\u5f53\u524d\u7ed3\u70b9\u7684\u9ed1\u8272\u7ed3\u70b9\u6570\u91cf\u3002\u6bcf\u9047\u5230\u4e00\u4e2a\u9ed1\u8272\u7ed3\u70b9&#xff0c;\u5c31\u6267\u884c &#043;&#043;blackNum&#xff1b;\u8d70\u5230\u7a7a\u7ed3\u70b9\u65f6&#xff0c;\u5c31\u5f97\u5230\u4e86\u4e00\u6761\u5b8c\u6574\u8def\u5f84\u4e0a\u7684\u9ed1\u8272\u7ed3\u70b9\u6570\u91cf\u3002<\/p>\n<p>\u4efb\u9009\u4e00\u6761\u8def\u5f84\u7684\u9ed1\u8272\u7ed3\u70b9\u6570\u91cf\u4f5c\u4e3a\u53c2\u8003\u503c&#xff0c;\u518d\u4f9d\u6b21\u6bd4\u8f83\u5176\u4ed6\u8def\u5f84\u3002\u5982\u679c\u5b58\u5728\u4e0d\u540c\u7684\u6570\u91cf&#xff0c;\u5c31\u8fdd\u53cd\u4e86\u89c4\u5219\u3002<\/p>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>bool Check(Node* root, int blackNum, const int refNum)<br \/>\n{<br \/>\n    if (root &#061;&#061; nullptr)<br \/>\n    {<br \/>\n        \/\/ \u904d\u5386\u5230\u7a7a\u7ed3\u70b9&#xff0c;\u610f\u5473\u7740\u4e00\u6761\u8def\u5f84\u8d70\u5b8c\u4e86<br \/>\n        if (refNum !&#061; blackNum)<br \/>\n        {<br \/>\n            cout &lt;&lt; &#034;\u5b58\u5728\u9ed1\u8272\u7ed3\u70b9\u6570\u91cf\u4e0d\u76f8\u7b49\u7684\u8def\u5f84&#034; &lt;&lt; endl;<br \/>\n            return false;<br \/>\n        }<br \/>\n        return true;<br \/>\n    }<br \/>\n    \/\/ \u68c0\u67e5\u5f53\u524d\u7ed3\u70b9\u548c\u7236\u4eb2\u662f\u5426\u90fd\u662f\u7ea2\u8272<br \/>\n    if (root-&gt;_col &#061;&#061; RED &amp;&amp; root-&gt;_parent-&gt;_col &#061;&#061; RED)<br \/>\n    {<br \/>\n        cout &lt;&lt; root-&gt;_kv.first &lt;&lt; &#034; \u5b58\u5728\u8fde\u7eed\u7684\u7ea2\u8272\u7ed3\u70b9&#034; &lt;&lt; endl;<br \/>\n        return false;<br \/>\n    }<br \/>\n    \/\/ \u8bb0\u5f55\u5f53\u524d\u8def\u5f84\u4e0a\u7684\u9ed1\u8272\u7ed3\u70b9\u6570\u91cf<br \/>\n    if (root-&gt;_col &#061;&#061; BLACK)<br \/>\n    {<br \/>\n        blackNum&#043;&#043;;<br \/>\n    }<br \/>\n    return Check(root-&gt;_left, blackNum, refNum)<br \/>\n        &amp;&amp; Check(root-&gt;_right, blackNum, refNum);<br \/>\n}<\/p>\n<p>bool IsBalance()<br \/>\n{<br \/>\n    \/\/ \u7a7a\u6811\u7b26\u5408\u7ea2\u9ed1\u6811\u89c4\u5219<br \/>\n    if (_root &#061;&#061; nullptr)<br \/>\n    {<br \/>\n        return true;<br \/>\n    }<br \/>\n    \/\/ \u6839\u7ed3\u70b9\u5fc5\u987b\u662f\u9ed1\u8272<br \/>\n    if (_root-&gt;_col &#061;&#061; RED)<br \/>\n    {<br \/>\n        return false;<br \/>\n    }<br \/>\n    \/\/ \u7edf\u8ba1\u6700\u5de6\u4fa7\u8def\u5f84\u4e0a\u7684\u9ed1\u8272\u7ed3\u70b9\u6570\u91cf&#xff0c;\u4f5c\u4e3a\u53c2\u8003\u503c<br \/>\n    int refNum &#061; 0;<br \/>\n    Node* cur &#061; _root;<br \/>\n    while (cur)<br \/>\n    {<br \/>\n        if (cur-&gt;_col &#061;&#061; BLACK)<br \/>\n        {<br \/>\n            &#043;&#043;refNum;<br \/>\n        }<br \/>\n        cur &#061; cur-&gt;_left;<br \/>\n    }<br \/>\n    return Check(_root, 0, refNum);<br \/>\n}<\/p>\n<p>\u8fd9\u91cc\u8bb2\u4e00\u4e0b\u601d\u8def&#xff1a;<\/p>\n<p>\u5148\u68c0\u67e5\u6839\u7ed3\u70b9&#xff0c;\u518d\u9009\u62e9\u4e00\u6761\u8def\u5f84\u4f5c\u4e3a\u53c2\u8003&#xff0c;\u6700\u540e\u9012\u5f52\u68c0\u67e5\u6574\u68f5\u6811\u3002<\/p>\n<li>\n<p>IsBalance()&#xff1a;\u68c0\u67e5\u6839\u7ed3\u70b9&#xff0c;\u786e\u5b9a\u53c2\u8003\u503c\u3002<\/p>\n<p>\u7a7a\u6811\u76f4\u63a5\u8fd4\u56de true&#xff1b;\u6839\u7ed3\u70b9\u4e3a\u7ea2\u8272&#xff0c;\u76f4\u63a5\u8fd4\u56de false\u3002<\/p>\n<p>\u63a5\u7740\u4ece\u6839\u7ed3\u70b9\u5f00\u59cb&#xff0c;\u4e00\u76f4\u5f80\u5de6\u8d70&#xff0c;\u7edf\u8ba1\u8fd9\u6761\u8def\u5f84\u4e0a\u7684\u9ed1\u8272\u7ed3\u70b9\u6570\u91cf&#xff0c;\u8bb0\u4e3a refNum\u3002\u9009\u6700\u5de6\u4fa7\u8def\u5f84\u53ea\u662f\u56e0\u4e3a\u65b9\u4fbf&#xff0c;\u4efb\u610f\u4e00\u6761\u4ece\u6839\u5230\u7a7a\u7ed3\u70b9\u7684\u8def\u5f84\u90fd\u53ef\u4ee5\u4f5c\u4e3a\u53c2\u8003\u3002<\/p>\n<\/li>\n<li>\n<p>Check()&#xff1a;\u7edf\u8ba1\u6bcf\u6761\u8def\u5f84\u4e0a\u7684\u9ed1\u8272\u7ed3\u70b9\u6570\u91cf\u3002<\/p>\n<p>blackNum \u8868\u793a\u5f53\u524d\u8def\u5f84\u4e0a\u5df2\u7ecf\u9047\u5230\u7684\u9ed1\u8272\u7ed3\u70b9\u6570\u91cf\u3002\u9047\u5230\u9ed1\u8272\u7ed3\u70b9&#xff0c;\u5c31\u6267\u884c blackNum&#043;&#043;\u3002<\/p>\n<p>\u5f53 root &#061;&#061; nullptr \u65f6&#xff0c;\u8bf4\u660e\u4e00\u6761\u8def\u5f84\u8d70\u5b8c\u4e86&#xff0c;\u6b64\u65f6\u6bd4\u8f83&#xff1a;<\/p>\n<p>refNum &#061;&#061; blackNum<\/p>\n<p>\u76f8\u7b49&#xff0c;\u8bf4\u660e\u8fd9\u6761\u8def\u5f84\u7b26\u5408\u8981\u6c42&#xff1b;\u4e0d\u76f8\u7b49&#xff0c;\u8bf4\u660e\u4e0d\u540c\u8def\u5f84\u4e0a\u7684\u9ed1\u8272\u7ed3\u70b9\u6570\u91cf\u4e0d\u4e00\u81f4\u3002<\/p>\n<p>\u8fd9\u91cc\u6ca1\u6709\u628a\u7a7a\u7ed3\u70b9\u8ba1\u5165\u9ed1\u8272\u7ed3\u70b9\u6570\u91cf&#xff0c;\u4f46\u6bcf\u6761\u8def\u5f84\u90fd\u91c7\u7528\u76f8\u540c\u7684\u7edf\u8ba1\u65b9\u5f0f&#xff0c;\u56e0\u6b64\u4e0d\u5f71\u54cd\u6bd4\u8f83\u7ed3\u679c\u3002<\/p>\n<\/li>\n<li>\n<p>\u9047\u5230\u7ea2\u8272\u7ed3\u70b9&#xff0c;\u68c0\u67e5\u5176\u7236\u4eb2\u7684\u989c\u8272\u3002<\/p>\n<p>if (root-&gt;_col &#061;&#061; RED &amp;&amp; root-&gt;_parent-&gt;_col &#061;&#061; RED)<\/p>\n<p>\u5f53\u524d\u7ed3\u70b9\u548c\u7236\u4eb2\u90fd\u662f\u7ea2\u8272&#xff0c;\u5c31\u51fa\u73b0\u4e86\u8fde\u7eed\u7684\u7ea2\u8272\u7ed3\u70b9&#xff0c;\u8fd4\u56de false\u3002<\/p>\n<p>\u8fd9\u91cc\u4f9d\u8d56 IsBalance() \u5df2\u7ecf\u68c0\u67e5\u6839\u7ed3\u70b9\u4e3a\u9ed1\u8272\u3002 \u68c0\u67e5\u5230\u6839\u7ed3\u70b9\u65f6&#xff0c;&amp;&amp; \u5de6\u4fa7\u4e3a\u5047&#xff0c;\u53f3\u4fa7\u4e0d\u4f1a\u6267\u884c&#xff0c;\u56e0\u6b64\u4e0d\u4f1a\u8bbf\u95ee\u6839\u7ed3\u70b9\u7684\u7a7a\u7236\u6307\u9488\u3002<\/p>\n<\/li>\n<li>\n<p>\u5de6\u53f3\u5b50\u6811\u90fd\u901a\u8fc7&#xff0c;\u5f53\u524d\u5b50\u6811\u624d\u901a\u8fc7\u3002<\/p>\n<p>return Check(root-&gt;_left, blackNum, refNum)<br \/>\n    &amp;&amp; Check(root-&gt;_right, blackNum, refNum);<\/p>\n<p>\u4efb\u610f\u4e00\u4fa7\u8fd4\u56de false&#xff0c;\u6574\u4f53\u5c31\u8fd4\u56de false\u3002<\/p>\n<p>blackNum \u6309\u503c\u4f20\u9012&#xff0c;\u5de6\u53f3\u9012\u5f52\u62ff\u5230\u7684\u662f\u5404\u81ea\u7684\u526f\u672c&#xff0c;\u6240\u4ee5\u5de6\u5b50\u6811\u5bf9\u8ba1\u6570\u7684\u4fee\u6539\u4e0d\u4f1a\u5f71\u54cd\u53f3\u5b50\u6811&#xff0c;\u4e5f\u4e0d\u9700\u8981\u5728\u9012\u5f52\u8fd4\u56de\u540e\u6267\u884c &#8211;blackNum\u3002<\/p>\n<\/li>\n<p>\u6700\u540e&#xff0c;\u5220\u9664\u8fd9\u4e2a\u90e8\u5206\u4f9d\u65e7\u4e0d\u8bb2&#xff0c;\u5982\u679c\u540e\u671f\u6211\u5b66\u4f1a\u4e86\u76f8\u5173\u7684\u64cd\u4f5c\u518d\u8003\u8651\u8981\u4e0d\u8981\u8865\u5145\u3002<\/p>\n<\/p>\n<p>\u603b\u7ed3&#xff1a;<\/p>\n<p>\u7ea2\u9ed1\u6811\u662f\u5728\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u57fa\u7840\u4e0a&#xff0c;\u901a\u8fc7\u989c\u8272\u89c4\u5219\u7ef4\u6301\u8fd1\u4f3c\u5e73\u8861\u7684\u6570\u636e\u7ed3\u6784&#xff0c;\u5176\u67e5\u627e\u3001\u63d2\u5165\u548c\u5220\u9664\u7684\u6700\u574f\u65f6\u95f4\u590d\u6742\u5ea6\u5747\u4e3a O(log N)\u3002\u63d2\u5165\u65f6&#xff0c;\u82e5\u51fa\u73b0\u8fde\u7eed\u7684\u7ea2\u8272\u7ed3\u70b9&#xff0c;\u5c31\u6839\u636e\u53d4\u53d4\u7ed3\u70b9\u7684\u989c\u8272\u53ca\u7ed3\u70b9\u7684\u4f4d\u7f6e&#xff0c;\u901a\u8fc7\u53d8\u8272\u3001\u5355\u65cb\u6216\u53cc\u65cb\u6062\u590d\u7ea2\u9ed1\u6811\u7684\u6027\u8d28\u3002\u9a8c\u8bc1\u65f6&#xff0c;\u5e94\u68c0\u67e5\u6839\u7ed3\u70b9\u4e3a\u9ed1\u8272\u3001\u4e0d\u5b58\u5728\u8fde\u7eed\u7ea2\u8272\u7ed3\u70b9&#xff0c;\u4ee5\u53ca\u5404\u6761\u4ece\u6839\u5230 NULL \u7684\u8def\u5f84\u4e0a\u9ed1\u8272\u7ed3\u70b9\u6570\u91cf\u76f8\u540c&#xff0c;\u4e0d\u80fd\u4ec5\u51ed\u6700\u957f\u8def\u5f84\u4e0d\u8d85\u8fc7\u6700\u77ed\u8def\u5f84\u7684\u4e24\u500d\u6765\u5224\u65ad\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u76ee\u6807:<br \/>\n1.\u638c\u63e1\u7ea2\u9ed1\u6811\u7684\u6982\u5ff5\u4e0e\u67d3\u8272\u8fc7\u7a0b2.\u5b66\u4f1a\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0\u6ce8\u610f&#xff1a;\u5b66\u4e60\u672c\u7247\u524d\u5fc5\u987b\u8981\u5b66\u4f1aAVL\u6811\u7684\u65cb\u8f6c\u3002\u4e00.\u7ea2\u9ed1\u6811\u7684\u6982\u5ff51.\u6982\u5ff5\u7ea2\u9ed1\u6811\u662f\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811&#xff0c;\u4ed6\u7684\u6bcf\u4e2a\u7ed3\u70b9\u589e\u52a0\u2f00\u4e2a\u5b58\u50a8\u4f4d\u6765\u8868\u793a\u7ed3\u70b9\u7684\u989c\u8272&#xff0c;\u53ef\u4ee5\u662f\u7ea2\u8272\u6216\u8005\u9ed1\u8272\u3002 \u901a\u8fc7\u5bf9\u4efb\u4f55\u4e00\u6761\u4ece\u6839\u5230\u53f6\u5b50\u7684\u8def\u5f84\u4e0a\u5404\u4e2a\u7ed3\u70b9\u7684\u989c\u8272\u8fdb\u884c\u7ea6\u675f&#xff0c;\u7ea2\u9ed1\u6811\u786e\u4fdd\u6ca1\u6709\u2f00\u6761\u8def\u5f84\u4f1a\u6bd4\u5176\u4ed6\u8def\u5f84\u957f\u51fa2\u500d&#xff0c;\u56e0\u800c\u662f\u63a5\u8fd1\u5e73\u8861\u7684\u3002\u5982\u56fe&#xff1a;2.\u89c4\u5219\u4e00\u68f5\u7ea2\u9ed1\u6811\u5fc5\u987b\u8981\u6ee1\u8db3\u4ee5\u4e0b\u7684\u89c4\u5219:.\u6bcf\u4e2a\u7ed3<\/p>\n","protected":false},"author":2,"featured_media":120494,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9139,55,1813,427],"topic":[],"class_list":["post-120508","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-9139","tag-c","tag-1813","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u4e8c\u5341):\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/120508.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u4e8c\u5341):\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u672c\u7bc7\u76ee\u6807: 1.\u638c\u63e1\u7ea2\u9ed1\u6811\u7684\u6982\u5ff5\u4e0e\u67d3\u8272\u8fc7\u7a0b2.\u5b66\u4f1a\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0\u6ce8\u610f&#xff1a;\u5b66\u4e60\u672c\u7247\u524d\u5fc5\u987b\u8981\u5b66\u4f1aAVL\u6811\u7684\u65cb\u8f6c\u3002\u4e00.\u7ea2\u9ed1\u6811\u7684\u6982\u5ff51.\u6982\u5ff5\u7ea2\u9ed1\u6811\u662f\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811&#xff0c;\u4ed6\u7684\u6bcf\u4e2a\u7ed3\u70b9\u589e\u52a0\u2f00\u4e2a\u5b58\u50a8\u4f4d\u6765\u8868\u793a\u7ed3\u70b9\u7684\u989c\u8272&#xff0c;\u53ef\u4ee5\u662f\u7ea2\u8272\u6216\u8005\u9ed1\u8272\u3002 \u901a\u8fc7\u5bf9\u4efb\u4f55\u4e00\u6761\u4ece\u6839\u5230\u53f6\u5b50\u7684\u8def\u5f84\u4e0a\u5404\u4e2a\u7ed3\u70b9\u7684\u989c\u8272\u8fdb\u884c\u7ea6\u675f&#xff0c;\u7ea2\u9ed1\u6811\u786e\u4fdd\u6ca1\u6709\u2f00\u6761\u8def\u5f84\u4f1a\u6bd4\u5176\u4ed6\u8def\u5f84\u957f\u51fa2\u500d&#xff0c;\u56e0\u800c\u662f\u63a5\u8fd1\u5e73\u8861\u7684\u3002\u5982\u56fe&#xff1a;2.\u89c4\u5219\u4e00\u68f5\u7ea2\u9ed1\u6811\u5fc5\u987b\u8981\u6ee1\u8db3\u4ee5\u4e0b\u7684\u89c4\u5219:.\u6bcf\u4e2a\u7ed3\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/120508.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-31T12:41:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124046-6ae5e1ce7a6af.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=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/120508.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/120508.html\",\"name\":\"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u4e8c\u5341):\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-31T12:41:05+00:00\",\"dateModified\":\"2026-10-31T12:41:05+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/120508.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/120508.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/120508.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u4e8c\u5341):\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u4e8c\u5341):\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/120508.html","og_locale":"zh_CN","og_type":"article","og_title":"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u4e8c\u5341):\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u672c\u7bc7\u76ee\u6807: 1.\u638c\u63e1\u7ea2\u9ed1\u6811\u7684\u6982\u5ff5\u4e0e\u67d3\u8272\u8fc7\u7a0b2.\u5b66\u4f1a\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0\u6ce8\u610f&#xff1a;\u5b66\u4e60\u672c\u7247\u524d\u5fc5\u987b\u8981\u5b66\u4f1aAVL\u6811\u7684\u65cb\u8f6c\u3002\u4e00.\u7ea2\u9ed1\u6811\u7684\u6982\u5ff51.\u6982\u5ff5\u7ea2\u9ed1\u6811\u662f\u4e00\u68f5\u4e8c\u53c9\u641c\u7d22\u6811&#xff0c;\u4ed6\u7684\u6bcf\u4e2a\u7ed3\u70b9\u589e\u52a0\u2f00\u4e2a\u5b58\u50a8\u4f4d\u6765\u8868\u793a\u7ed3\u70b9\u7684\u989c\u8272&#xff0c;\u53ef\u4ee5\u662f\u7ea2\u8272\u6216\u8005\u9ed1\u8272\u3002 \u901a\u8fc7\u5bf9\u4efb\u4f55\u4e00\u6761\u4ece\u6839\u5230\u53f6\u5b50\u7684\u8def\u5f84\u4e0a\u5404\u4e2a\u7ed3\u70b9\u7684\u989c\u8272\u8fdb\u884c\u7ea6\u675f&#xff0c;\u7ea2\u9ed1\u6811\u786e\u4fdd\u6ca1\u6709\u2f00\u6761\u8def\u5f84\u4f1a\u6bd4\u5176\u4ed6\u8def\u5f84\u957f\u51fa2\u500d&#xff0c;\u56e0\u800c\u662f\u63a5\u8fd1\u5e73\u8861\u7684\u3002\u5982\u56fe&#xff1a;2.\u89c4\u5219\u4e00\u68f5\u7ea2\u9ed1\u6811\u5fc5\u987b\u8981\u6ee1\u8db3\u4ee5\u4e0b\u7684\u89c4\u5219:.\u6bcf\u4e2a\u7ed3","og_url":"https:\/\/www.wsisp.com\/helps\/120508.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-31T12:41:05+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031124046-6ae5e1ce7a6af.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/120508.html","url":"https:\/\/www.wsisp.com\/helps\/120508.html","name":"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u4e8c\u5341):\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-31T12:41:05+00:00","dateModified":"2026-10-31T12:41:05+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/120508.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/120508.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/120508.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u4e8c\u5341):\u7ea2\u9ed1\u6811\u7684\u5b9e\u73b0"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/120508","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=120508"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/120508\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/120494"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=120508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=120508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=120508"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=120508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}