{"id":91093,"date":"2026-08-06T21:08:41","date_gmt":"2026-08-06T13:08:41","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/91093.html"},"modified":"2026-08-06T21:08:41","modified_gmt":"2026-08-06T13:08:41","slug":"c-list-%e6%ba%90%e7%a0%81%e7%ba%a7%e6%b7%b1%e5%ba%a6%e6%8b%86%e8%a7%a3-%e5%8f%8c%e5%90%91%e5%be%aa%e7%8e%af%e9%93%be%e8%a1%a8%e7%9a%84%e4%bc%98%e9%9b%85%e4%b8%8e%e4%bb%a3%e4%bb%b7","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/91093.html","title":{"rendered":"C++ : list \u6e90\u7801\u7ea7\u6df1\u5ea6\u62c6\u89e3\u2014\u2014\u53cc\u5411\u5faa\u73af\u94fe\u8868\u7684\u4f18\u96c5\u4e0e\u4ee3\u4ef7"},"content":{"rendered":"<p>\u5728 STL \u987a\u5e8f\u5bb9\u5668\u4e09\u5de8\u5934\u4e2d&#xff0c;list \u662f\u6700\u201c\u7eaf\u7cb9\u201d\u7684\u94fe\u5f0f\u7ed3\u6784\u4ee3\u8868&#xff1a;vector \u4e3b\u6253\u8fde\u7eed\u5185\u5b58\u7684\u6781\u81f4\u8bbf\u95ee\u6548\u7387&#xff0c;deque \u4e3b\u6253\u53cc\u7aef\u64cd\u4f5c\u7684\u6298\u4e2d\u5e73\u8861&#xff0c;list \u5219\u628a\u4efb\u610f\u4f4d\u7f6e\u63d2\u5220\u7684\u80fd\u529b\u62c9\u6ee1&#xff0c;\u4ee3\u4ef7\u662f\u5f7b\u5e95\u653e\u5f03\u968f\u673a\u8bbf\u95ee\u4e0e\u7f13\u5b58\u53cb\u597d\u6027\u3002<\/p>\n<p>\u5b83\u7684\u5e95\u5c42\u662f\u7ecf\u5178\u7684\u53cc\u5411\u5faa\u73af\u94fe\u8868&#xff0c;\u5b9e\u73b0\u770b\u4f3c\u7b80\u5355&#xff0c;\u5b9e\u5219\u85cf\u7740\u5927\u91cf STL \u7684\u8bbe\u8ba1\u5de7\u601d\u2014\u2014\u6bd4\u5982\u54e8\u5175\u8282\u70b9\u3001\u5206\u5c42\u8282\u70b9\u7ed3\u6784\u3001\u4e13\u5c5e\u6210\u5458\u7b97\u6cd5\u7b49\u3002\u672c\u6587\u57fa\u4e8e GCC libstdc&#043;&#043; \u6e90\u7801&#xff0c;\u4ece\u5185\u5b58\u5e03\u5c40\u3001\u8fed\u4ee3\u5668\u5b9e\u73b0\u3001\u6838\u5fc3\u64cd\u4f5c\u5230\u6027\u80fd\u6743\u8861&#xff0c;\u4e00\u5c42\u5c42\u6252\u900f list \u7684\u5e95\u5c42\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u6574\u4f53\u67b6\u6784&#xff1a;\u53cc\u5411\u5faa\u73af\u94fe\u8868 &#043; \u54e8\u5175\u8282\u70b9<\/h3>\n<p>list \u7684\u6838\u5fc3\u8bbe\u8ba1\u53ea\u6709\u4e24\u4e2a\u8981\u70b9&#xff1a;\u7528\u53cc\u5411\u94fe\u8868\u4fdd\u8bc1\u4efb\u610f\u4f4d\u7f6e O(1) \u63d2\u5220&#xff0c;\u7528\u54e8\u5175\u8282\u70b9\u7edf\u4e00\u8fb9\u754c\u5904\u7406&#xff0c;\u6d88\u9664\u7a7a\u94fe\u8868\u3001\u5934\u5c3e\u8282\u70b9\u7684\u5206\u652f\u5224\u65ad\u3002<\/p>\n<h4>1.1 \u8282\u70b9\u7684\u5206\u5c42\u8bbe\u8ba1<\/h4>\n<p>STL \u6ca1\u6709\u628a\u6570\u636e\u548c\u6307\u9488\u585e\u5728\u540c\u4e00\u4e2a\u7ed3\u6784\u4f53\u91cc\u76f4\u63a5\u7528&#xff0c;\u800c\u662f\u505a\u4e86\u57fa\u7c7b&#043;\u6d3e\u751f\u7c7b\u7684\u5206\u5c42\u8bbe\u8ba1&#xff0c;\u628a\u94fe\u8868\u7ed3\u6784\u548c\u6570\u636e\u89e3\u8026\u3002<\/p>\n<p>\u5e95\u5c42\u57fa\u7c7b&#xff1a;\u53ea\u8d1f\u8d23\u94fe\u8868\u7ed3\u6784<\/p>\n<p><span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">_List_node_base<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    _List_node_base<span class=\"token operator\">*<\/span> _M_next<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u540e\u7ee7\u6307\u9488<\/span><br \/>\n    _List_node_base<span class=\"token operator\">*<\/span> _M_prev<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u524d\u9a71\u6307\u9488<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd9\u4e2a\u57fa\u7c7b\u53ea\u5b58\u4e24\u4e2a\u6307\u9488&#xff0c;\u548c\u5143\u7d20\u7c7b\u578b\u5b8c\u5168\u65e0\u5173&#xff0c;\u6240\u6709\u94fe\u8868\u901a\u7528\u64cd\u4f5c&#xff08;\u8282\u70b9\u79fb\u52a8\u3001\u62fc\u63a5\u3001\u53cd\u8f6c&#xff09;\u90fd\u53ef\u4ee5\u57fa\u4e8e\u57fa\u7c7b\u6307\u9488\u5b9e\u73b0&#xff0c;\u4e0d\u7528\u5173\u5fc3\u6570\u636e\u7c7b\u578b&#xff0c;\u5927\u5e45\u51cf\u5c11\u4ee3\u7801\u5197\u4f59\u3002<\/p>\n<p>\u6d3e\u751f\u7c7b&#xff1a;\u8d1f\u8d23\u627f\u8f7d\u6570\u636e<\/p>\n<p><span class=\"token keyword\">template<\/span> <span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">typename<\/span> <span class=\"token class-name\">_Tp<\/span><span class=\"token operator\">&gt;<\/span><br \/>\n<span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">_List_node<\/span> <span class=\"token operator\">:<\/span> <span class=\"token base-clause\"><span class=\"token keyword\">public<\/span> <span class=\"token class-name\">_List_node_base<\/span><\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    _Tp _M_data<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u5b9e\u9645\u5b58\u50a8\u7684\u5143\u7d20\u6570\u636e<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u7ee7\u627f\u57fa\u7c7b\u7684\u6307\u9488\u80fd\u529b&#xff0c;\u518d\u52a0\u4e0a\u6570\u636e\u6210\u5458&#xff0c;\u5c31\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u94fe\u8868\u8282\u70b9\u3002<\/p>\n<h4>1.2 \u54e8\u5175\u8282\u70b9&#xff1a;\u6d88\u9664\u8fb9\u754c\u5224\u65ad\u7684\u795e\u6765\u4e4b\u7b14<\/h4>\n<p>list \u5bb9\u5668\u672c\u8eab\u53ea\u6301\u6709\u4e00\u4e2a\u6307\u9488\u2014\u2014\u6307\u5411\u54e8\u5175\u8282\u70b9&#xff08;Sentinel Node&#xff09;\u7684 _M_node\u3002\u54e8\u5175\u662f\u4e00\u4e2a\u4e0d\u5b58\u6709\u6548\u6570\u636e\u7684\u865a\u62df\u8282\u70b9&#xff0c;\u7528\u6765\u628a\u94fe\u8868\u9996\u5c3e\u8fde\u8d77\u6765\u5f62\u6210\u95ed\u73af\u3002<\/p>\n<ul>\n<li>\u7a7a\u94fe\u8868\u72b6\u6001&#xff1a;\u54e8\u5175\u7684 _M_next \u548c _M_prev \u90fd\u6307\u5411\u81ea\u5df1<\/li>\n<li>\u6709\u5143\u7d20\u72b6\u6001&#xff1a;\n<ul>\n<li>\u54e8\u5175-&gt;_M_next \u2192 \u7b2c\u4e00\u4e2a\u5143\u7d20\u8282\u70b9&#xff08;\u5bf9\u5e94 begin()&#xff09;<\/li>\n<li>\u54e8\u5175-&gt;_M_prev \u2192 \u6700\u540e\u4e00\u4e2a\u5143\u7d20\u8282\u70b9&#xff08;\u5bf9\u5e94 &#8211;end()&#xff09;<\/li>\n<li>\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u7684 _M_next \u2192 \u54e8\u5175<\/li>\n<li>\u7b2c\u4e00\u4e2a\u8282\u70b9\u7684 _M_prev \u2192 \u54e8\u5175<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u8fd9\u4e2a\u8bbe\u8ba1\u7684\u597d\u5904\u975e\u5e38\u76f4\u89c2&#xff1a;<\/p>\n<ul>\n<li>\u63d2\u5165\u3001\u5220\u9664\u64cd\u4f5c\u4e0d\u9700\u8981\u7279\u5224\u201c\u7a7a\u94fe\u8868\u201d\u201c\u5934\u8282\u70b9\u201d\u201c\u5c3e\u8282\u70b9\u201d\u7b49\u8fb9\u754c\u60c5\u51b5&#xff0c;\u6240\u6709\u4f4d\u7f6e\u7684\u64cd\u4f5c\u903b\u8f91\u5b8c\u5168\u4e00\u81f4<\/li>\n<li>end() \u8fed\u4ee3\u5668\u76f4\u63a5\u6307\u5411\u54e8\u5175&#xff0c;\u5929\u7136\u5c31\u662f\u201c\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u4e0b\u4e00\u4e2a\u4f4d\u7f6e\u201d&#xff0c;\u8bed\u4e49\u5b8c\u7f8e\u5339\u914d<\/li>\n<\/ul>\n<h4>1.3 \u5bb9\u5668\u7684\u6838\u5fc3\u6570\u636e\u6210\u5458<\/h4>\n<p>list \u7684\u6570\u636e\u6210\u5458\u6781\u7b80&#xff0c;\u5168\u90e8\u5b9a\u4e49\u5728\u57fa\u7c7b _List_base \u4e2d&#xff1a;<\/p>\n<p><span class=\"token keyword\">template<\/span> <span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">typename<\/span> <span class=\"token class-name\">_Tp<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">typename<\/span> <span class=\"token class-name\">_Alloc<\/span><span class=\"token operator\">&gt;<\/span><br \/>\n<span class=\"token keyword\">class<\/span> <span class=\"token class-name\">_List_base<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">protected<\/span><span class=\"token operator\">:<\/span><br \/>\n    _List_node_base<span class=\"token operator\">*<\/span> _M_node<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u6307\u5411\u54e8\u5175\u8282\u70b9\u7684\u552f\u4e00\u6307\u9488<\/span><br \/>\n    size_t _M_size<span class=\"token punctuation\">;<\/span>            <span class=\"token comment\">\/\/ \u5143\u7d20\u603b\u6570&#xff0c;C&#043;&#043;11 \u540e\u52a0\u5165<\/span><br \/>\n    <span class=\"token comment\">\/\/ &#8230; \u5206\u914d\u5668\u76f8\u5173\u6210\u5458<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd9\u91cc\u6709\u4e00\u4e2a\u7ecf\u5178\u9762\u8bd5\u8003\u70b9&#xff1a;<\/p>\n<p>C&#043;&#043;11 \u4e4b\u524d&#xff0c;list \u7684 size() \u662f O(n) \u65f6\u95f4\u590d\u6742\u5ea6\u3002\u65e9\u671f\u5b9e\u73b0\u6ca1\u6709 _M_size \u6210\u5458&#xff0c;\u8c03\u7528 size() \u65f6\u4f1a\u904d\u5386\u6574\u4e2a\u94fe\u8868\u8ba1\u6570\u3002C&#043;&#043;11 \u6807\u51c6\u5f3a\u5236\u8981\u6c42\u6240\u6709\u5bb9\u5668\u7684 size() \u4e3a\u5e38\u6570\u65f6\u95f4&#xff0c;libstdc&#043;&#043; \u624d\u52a0\u5165\u4e86 _M_size \u6210\u5458&#xff0c;\u6bcf\u6b21\u63d2\u5165\u5220\u9664\u90fd\u540c\u6b65\u7ef4\u62a4\u8ba1\u6570\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u7075\u9b42\u90e8\u4ef6&#xff1a;\u53cc\u5411\u8fed\u4ee3\u5668\u7684\u5b9e\u73b0<\/h3>\n<p>list \u4e0d\u652f\u6301\u968f\u673a\u8bbf\u95ee&#xff0c;\u5b83\u7684\u8fed\u4ee3\u5668\u662f\u53cc\u5411\u8fed\u4ee3\u5668&#xff08;Bidirectional Iterator&#xff09;&#xff0c;\u53ea\u80fd\u524d\u540e\u9010\u4e2a\u79fb\u52a8&#xff0c;\u4e0d\u80fd\u8df3\u8dc3\u3002<\/p>\n<h4>2.1 \u8fed\u4ee3\u5668\u7684\u6570\u636e\u7ed3\u6784<\/h4>\n<p>\u8fed\u4ee3\u5668\u672c\u8eab\u975e\u5e38\u8f7b\u91cf&#xff0c;\u5185\u90e8\u53ea\u6709\u4e00\u4e2a\u6307\u9488&#xff1a;<\/p>\n<p><span class=\"token keyword\">template<\/span> <span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">typename<\/span> <span class=\"token class-name\">_Tp<\/span><span class=\"token operator\">&gt;<\/span><br \/>\n<span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">_List_iterator<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    _List_node_base<span class=\"token operator\">*<\/span> _M_node<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u6307\u5411\u5f53\u524d\u8282\u70b9\u7684\u57fa\u7c7b\u6307\u9488<\/span><br \/>\n    <span class=\"token comment\">\/\/ &#8230; \u7c7b\u578b\u5b9a\u4e49<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u7528\u57fa\u7c7b\u6307\u9488\u800c\u4e0d\u662f\u6d3e\u751f\u7c7b\u6307\u9488\u7684\u539f\u56e0\u5f88\u7b80\u5355&#xff1a;\u8fed\u4ee3\u5668\u53ea\u9700\u8981\u64cd\u4f5c prev\/next \u6307\u9488&#xff0c;\u4e0d\u9700\u8981\u5173\u5fc3\u6570\u636e\u7c7b\u578b&#xff0c;const \u8fed\u4ee3\u5668\u4e5f\u53ef\u4ee5\u590d\u7528\u8fd9\u5957\u7ed3\u6784\u3002<\/p>\n<h4>2.2 \u6838\u5fc3\u8fd0\u7b97\u7b26\u91cd\u8f7d<\/h4>\n<p>\u8fed\u4ee3\u5668\u7684\u6240\u6709\u64cd\u4f5c\u672c\u8d28\u90fd\u662f\u5728\u64cd\u4f5c\u5185\u90e8\u7684\u8282\u70b9\u6307\u9488\u3002<\/p>\n<p>1. \u89e3\u5f15\u7528\u4e0e\u6210\u5458\u8bbf\u95ee<\/p>\n<p>_Tp<span class=\"token operator\">&amp;<\/span> <span class=\"token keyword\">operator<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">const<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5411\u4e0b\u8f6c\u578b\u4e3a\u6570\u636e\u8282\u70b9&#xff0c;\u53d6\u6570\u636e<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token generic-function\"><span class=\"token function\">static_cast<\/span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;<\/span>_List_node<span class=\"token operator\">&lt;<\/span>_Tp<span class=\"token operator\">&gt;<\/span><span class=\"token operator\">*<\/span><span class=\"token operator\">&gt;<\/span><\/span><\/span><span class=\"token punctuation\">(<\/span>_M_node<span class=\"token punctuation\">)<\/span><span class=\"token operator\">-&gt;<\/span>_M_data<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>_Tp<span class=\"token operator\">*<\/span> <span class=\"token keyword\">operator<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">const<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token operator\">&amp;<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">operator<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>2. \u524d\u540e\u79fb\u52a8<\/p>\n<p><span class=\"token comment\">\/\/ \u524d\u7f6e&#043;&#043;<\/span><br \/>\n_List_iterator<span class=\"token operator\">&amp;<\/span> <span class=\"token keyword\">operator<\/span><span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    _M_node <span class=\"token operator\">&#061;<\/span> _M_node<span class=\"token operator\">-&gt;<\/span>_M_next<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token operator\">*<\/span><span class=\"token keyword\">this<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u524d\u7f6e&#8211;<\/span><br \/>\n_List_iterator<span class=\"token operator\">&amp;<\/span> <span class=\"token keyword\">operator<\/span><span class=\"token operator\">&#8212;<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    _M_node <span class=\"token operator\">&#061;<\/span> _M_node<span class=\"token operator\">-&gt;<\/span>_M_prev<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token operator\">*<\/span><span class=\"token keyword\">this<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6ca1\u6709\u4efb\u4f55\u8ba1\u7b97&#xff0c;\u7eaf\u6307\u9488\u8df3\u8f6c&#xff0c;\u5355\u6b65\u64cd\u4f5c\u662f O(1)&#xff0c;\u4f46\u8981\u8d70\u5230\u7b2c n \u4e2a\u4f4d\u7f6e\u5c31\u5fc5\u987b\u4e00\u6b65\u4e00\u6b65\u8df3&#xff0c;\u6574\u4f53 O(n)\u3002<\/p>\n<h4>2.3 \u8fed\u4ee3\u5668\u7684\u80fd\u529b\u8fb9\u754c<\/h4>\n<p>\u5b83\u5c5e\u4e8e\u53cc\u5411\u8fed\u4ee3\u5668&#xff0c;\u53ea\u652f\u6301 &#043;&#043;\u3001&#8211;&#xff0c;\u4e0d\u652f\u6301 &#043;&#061;\u3001-&#061;\u3001[] \u7b49\u968f\u673a\u8bbf\u95ee\u64cd\u4f5c\u3002\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48 std::sort \u4e0d\u80fd\u76f4\u63a5\u4f5c\u7528\u4e8e list\u2014\u2014\u6807\u51c6\u6392\u5e8f\u7b97\u6cd5\u8981\u6c42\u968f\u673a\u8bbf\u95ee\u8fed\u4ee3\u5668\u6765\u652f\u6491\u5206\u6cbb\u3001\u7d22\u5f15\u8df3\u8dc3\u3002<\/p>\n<p>\u4e5f\u6b63\u56e0\u4e3a\u8fd9\u4e2a\u9650\u5236&#xff0c;list \u4e0d\u5f97\u4e0d\u81ea\u5df1\u5b9e\u73b0\u4e86\u4e00\u5957\u4e13\u5c5e\u7684\u6210\u5458\u7b97\u6cd5&#xff0c;\u540e\u9762\u4f1a\u8be6\u7ec6\u8bb2\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u6838\u5fc3\u64cd\u4f5c\u7684\u6e90\u7801\u7ea7\u6d41\u7a0b<\/h3>\n<h4>3.1 \u63d2\u5165\u64cd\u4f5c&#xff1a;O(1) \u7684\u672c\u8d28\u662f\u6539\u4e24\u4e2a\u6307\u9488<\/h4>\n<p>\u6240\u6709\u63d2\u5165\u64cd\u4f5c&#xff08;push_back\u3001push_front\u3001insert&#xff09;\u6700\u7ec8\u90fd\u4f1a\u8c03\u7528\u5e95\u5c42\u7684 _M_insert \u51fd\u6570&#xff0c;\u903b\u8f91\u5b8c\u5168\u7edf\u4e00&#xff0c;\u4e0d\u9700\u8981\u533a\u5206\u5934\u5c3e\u548c\u4e2d\u95f4\u4f4d\u7f6e\u3002<\/p>\n<p><span class=\"token comment\">\/\/ \u5728 position \u6307\u5411\u7684\u8282\u70b9\u4e4b\u524d\u63d2\u5165\u65b0\u8282\u70b9<\/span><br \/>\niterator <span class=\"token function\">_M_insert<\/span><span class=\"token punctuation\">(<\/span>iterator __position<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">const<\/span> _Tp<span class=\"token operator\">&amp;<\/span> __x<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    _List_node<span class=\"token operator\">&lt;<\/span>_Tp<span class=\"token operator\">&gt;<\/span><span class=\"token operator\">*<\/span> __new_node <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">_M_create_node<\/span><span class=\"token punctuation\">(<\/span>__x<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u5206\u914d\u65b0\u8282\u70b9<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u56db\u6b65\u6307\u9488\u64cd\u4f5c&#xff0c;\u5b8c\u6210\u63d2\u5165<\/span><br \/>\n    __new_node<span class=\"token operator\">-&gt;<\/span>_M_next <span class=\"token operator\">&#061;<\/span> __position<span class=\"token punctuation\">.<\/span>_M_node<span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ \u65b0\u8282\u70b9\u540e\u7ee7 &#061; \u76ee\u6807\u8282\u70b9<\/span><br \/>\n    __new_node<span class=\"token operator\">-&gt;<\/span>_M_prev <span class=\"token operator\">&#061;<\/span> __position<span class=\"token punctuation\">.<\/span>_M_node<span class=\"token operator\">-&gt;<\/span>_M_prev<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u65b0\u8282\u70b9\u524d\u9a71 &#061; \u76ee\u6807\u8282\u70b9\u7684\u524d\u9a71<\/span><br \/>\n    __position<span class=\"token punctuation\">.<\/span>_M_node<span class=\"token operator\">-&gt;<\/span>_M_prev<span class=\"token operator\">-&gt;<\/span>_M_next <span class=\"token operator\">&#061;<\/span> __new_node<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u524d\u9a71\u8282\u70b9\u7684\u540e\u7ee7 &#061; \u65b0\u8282\u70b9<\/span><br \/>\n    __position<span class=\"token punctuation\">.<\/span>_M_node<span class=\"token operator\">-&gt;<\/span>_M_prev <span class=\"token operator\">&#061;<\/span> __new_node<span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ \u76ee\u6807\u8282\u70b9\u7684\u524d\u9a71 &#061; \u65b0\u8282\u70b9<\/span><\/p>\n<p>    <span class=\"token operator\">&#043;&#043;<\/span>_M_size<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u7ef4\u62a4\u8ba1\u6570<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token function\">iterator<\/span><span class=\"token punctuation\">(<\/span>__new_node<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u56db\u6b65\u6307\u9488\u64cd\u4f5c&#xff0c;\u548c\u4f4d\u7f6e\u5b8c\u5168\u65e0\u5173\u2014\u2014\u63d2\u5728\u5934\u3001\u63d2\u5728\u5c3e\u3001\u63d2\u5728\u4e2d\u95f4&#xff0c;\u4ee3\u7801\u4e00\u6a21\u4e00\u6837&#xff0c;\u8fd9\u5c31\u662f\u54e8\u5175\u8282\u70b9\u5e26\u6765\u7684\u597d\u5904\u3002<\/p>\n<p>\u5173\u952e\u7279\u6027&#xff1a;\u63d2\u5165\u64cd\u4f5c\u4e0d\u4f1a\u5bfc\u81f4\u4efb\u4f55\u5df2\u6709\u8fed\u4ee3\u5668\u3001\u5f15\u7528\u3001\u6307\u9488\u5931\u6548\u3002\u6240\u6709\u5df2\u6709\u8282\u70b9\u7684\u5185\u5b58\u5730\u5740\u90fd\u6ca1\u6709\u53d8\u5316&#xff0c;\u53ea\u662f\u6307\u9488\u6307\u5411\u53d8\u4e86\u3002<\/p>\n<h4>3.2 \u5220\u9664\u64cd\u4f5c&#xff1a;\u53ea\u8ba9\u88ab\u5220\u8282\u70b9\u5931\u6548<\/h4>\n<p>\u5220\u9664\u64cd\u4f5c\u548c\u63d2\u5165\u5bf9\u79f0&#xff0c;\u53ea\u9700\u8981\u4fee\u6539\u524d\u540e\u8282\u70b9\u7684\u6307\u9488&#xff0c;\u7136\u540e\u91ca\u653e\u76ee\u6807\u8282\u70b9\u3002<\/p>\n<p>iterator <span class=\"token function\">_M_erase<\/span><span class=\"token punctuation\">(<\/span>iterator __position<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    _List_node_base<span class=\"token operator\">*<\/span> __next_node <span class=\"token operator\">&#061;<\/span> __position<span class=\"token punctuation\">.<\/span>_M_node<span class=\"token operator\">-&gt;<\/span>_M_next<span class=\"token punctuation\">;<\/span><br \/>\n    _List_node_base<span class=\"token operator\">*<\/span> __prev_node <span class=\"token operator\">&#061;<\/span> __position<span class=\"token punctuation\">.<\/span>_M_node<span class=\"token operator\">-&gt;<\/span>_M_prev<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u524d\u540e\u8282\u70b9\u76f4\u63a5\u4e92\u8fde&#xff0c;\u8df3\u8fc7\u88ab\u5220\u8282\u70b9<\/span><br \/>\n    __prev_node<span class=\"token operator\">-&gt;<\/span>_M_next <span class=\"token operator\">&#061;<\/span> __next_node<span class=\"token punctuation\">;<\/span><br \/>\n    __next_node<span class=\"token operator\">-&gt;<\/span>_M_prev <span class=\"token operator\">&#061;<\/span> __prev_node<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token function\">_M_destroy_node<\/span><span class=\"token punctuation\">(<\/span><span class=\"token generic-function\"><span class=\"token function\">static_cast<\/span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;<\/span>_List_node<span class=\"token operator\">&lt;<\/span>_Tp<span class=\"token operator\">&gt;<\/span><span class=\"token operator\">*<\/span><span class=\"token operator\">&gt;<\/span><\/span><\/span><span class=\"token punctuation\">(<\/span>__position<span class=\"token punctuation\">.<\/span>_M_node<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u91ca\u653e\u8282\u70b9<\/span><br \/>\n    <span class=\"token operator\">&#8212;<\/span>_M_size<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token function\">iterator<\/span><span class=\"token punctuation\">(<\/span>__next_node<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8fed\u4ee3\u5668\u5931\u6548\u89c4\u5219&#xff1a;\u53ea\u6709\u88ab\u5220\u9664\u7684\u90a3\u4e2a\u8282\u70b9\u7684\u8fed\u4ee3\u5668\u3001\u5f15\u7528\u3001\u6307\u9488\u4f1a\u5931\u6548&#xff0c;\u5176\u4f59\u6240\u6709\u8282\u70b9\u5168\u90e8\u4e0d\u53d7\u5f71\u54cd\u3002\u8fd9\u662f\u6240\u6709 STL \u5bb9\u5668\u91cc\u8fed\u4ee3\u5668\u7a33\u5b9a\u6027\u6700\u5f3a\u7684\u8868\u73b0\u3002<\/p>\n<h4>3.3 \u72ec\u95e8\u7edd\u6280&#xff1a;splice \u94fe\u8868\u62fc\u63a5<\/h4>\n<p>splice \u662f list \u72ec\u6709\u7684\u64cd\u4f5c&#xff0c;\u4e5f\u662f\u94fe\u8868\u7ed3\u6784\u7684\u4ef7\u503c\u5929\u82b1\u677f\u2014\u2014\u5b83\u53ef\u4ee5\u628a\u53e6\u4e00\u4e2a list \u7684\u8282\u70b9\u76f4\u63a5\u201c\u526a\u201d\u8fc7\u6765&#xff0c;\u96f6\u62f7\u8d1d\u3001\u96f6\u5143\u7d20\u6784\u9020\u6790\u6784&#xff0c;\u7eaf\u6307\u9488\u64cd\u4f5c\u3002<\/p>\n<p>\u5b83\u6709\u4e09\u79cd\u5e38\u7528\u91cd\u8f7d&#xff1a;<\/p>\n<li>splice(pos, other)&#xff1a;\u628a other \u6574\u4e2a\u94fe\u8868\u79fb\u52a8\u5230 pos \u524d\u9762&#xff0c;other \u53d8\u4e3a\u7a7a<\/li>\n<li>splice(pos, other, it)&#xff1a;\u628a other \u4e2d it \u6307\u5411\u7684\u5355\u4e2a\u8282\u70b9\u79fb\u52a8\u8fc7\u6765<\/li>\n<li>splice(pos, other, first, last)&#xff1a;\u628a other \u7684 [first, last) \u533a\u95f4\u79fb\u52a8\u8fc7\u6765<\/li>\n<h5>\u65f6\u95f4\u590d\u6742\u5ea6\u7684\u7ec6\u8282<\/h5>\n<ul>\n<li>\u6574\u4e2a\u94fe\u8868\u8f6c\u79fb\u3001\u5355\u4e2a\u8282\u70b9\u8f6c\u79fb&#xff1a;O(1)&#xff0c;\u53ea\u6539\u6307\u9488&#xff0c;\u76f4\u63a5\u590d\u7528 other \u7684\u603b\u5927\u5c0f\u66f4\u65b0\u8ba1\u6570<\/li>\n<li>\u533a\u95f4\u8f6c\u79fb&#xff1a;O(k)&#xff08;k \u4e3a\u533a\u95f4\u5143\u7d20\u4e2a\u6570&#xff09;&#xff0c;\u56e0\u4e3a\u9700\u8981\u904d\u5386\u533a\u95f4\u7edf\u8ba1\u5143\u7d20\u4e2a\u6570\u6765\u66f4\u65b0 _M_size<\/li>\n<li>\u6ce8&#xff1a;C&#043;&#043;11 \u4e4b\u524d\u6ca1\u6709 _M_size&#xff0c;\u6240\u6709 splice \u90fd\u662f\u7eaf O(1)<\/li>\n<\/ul>\n<p>splice \u7684\u5178\u578b\u5e94\u7528\u573a\u666f\u662f LRU \u7f13\u5b58&#xff1a;\u628a\u521a\u8bbf\u95ee\u7684\u8282\u70b9\u4ece\u94fe\u8868\u4e2d\u95f4\u79fb\u5230\u8868\u5934&#xff0c;\u5168\u7a0b\u4e0d\u9700\u8981\u62f7\u8d1d\u6570\u636e&#xff0c;\u6027\u80fd\u6781\u9ad8\u3002<\/p>\n<h4>3.4 \u4e13\u5c5e\u6210\u5458\u7b97\u6cd5&#xff1a;\u4e3a\u4ec0\u4e48\u4e0d\u76f4\u63a5\u7528 STL \u901a\u7528\u7b97\u6cd5<\/h4>\n<p>list \u81ea\u5e26 sort\u3001merge\u3001reverse\u3001unique\u3001remove \u7b49\u6210\u5458\u51fd\u6570&#xff0c;\u4e0d\u662f\u91cd\u590d\u9020\u8f6e\u5b50&#xff0c;\u800c\u662f\u901a\u7528\u7b97\u6cd5\u8981\u4e48\u7528\u4e0d\u4e86&#xff0c;\u8981\u4e48\u6548\u7387\u592a\u4f4e\u3002<\/p>\n<table>\n<tr>\u7b97\u6cd5\u4e3a\u4ec0\u4e48\u81ea\u5df1\u5b9e\u73b0\u5e95\u5c42\u5b9e\u73b0<\/tr>\n<tbody>\n<tr>\n<td>sort<\/td>\n<td>std::sort \u9700\u8981\u968f\u673a\u8bbf\u95ee\u8fed\u4ee3\u5668&#xff0c;list \u4e0d\u652f\u6301<\/td>\n<td>\u8fed\u4ee3\u7248\u81ea\u5e95\u5411\u4e0a\u5f52\u5e76\u6392\u5e8f&#xff0c;\u7a7a\u95f4 O(1)&#xff0c;\u65f6\u95f4 O(n log n)&#xff0c;\u7a33\u5b9a\u6392\u5e8f<\/td>\n<\/tr>\n<tr>\n<td>merge<\/td>\n<td>\u901a\u7528 std::merge \u9700\u8981\u62f7\u8d1d\u5143\u7d20&#xff0c;list \u53ef\u4ee5\u76f4\u63a5\u642c\u8282\u70b9<\/td>\n<td>\u6307\u9488\u64cd\u4f5c\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868&#xff0c;\u96f6\u62f7\u8d1d<\/td>\n<\/tr>\n<tr>\n<td>reverse<\/td>\n<td>\u901a\u7528\u7b97\u6cd5\u53ef\u4ee5\u7528&#xff0c;\u4f46\u6210\u5458\u51fd\u6570\u53ef\u4ee5\u76f4\u63a5\u6279\u91cf\u4ea4\u6362\u6307\u9488&#xff0c;\u6548\u7387\u66f4\u9ad8<\/td>\n<td>\u904d\u5386\u4ea4\u6362\u6bcf\u4e2a\u8282\u70b9\u7684 prev\/next<\/td>\n<\/tr>\n<tr>\n<td>unique \/ remove<\/td>\n<td>\u901a\u7528 erase-remove \u4f1a\u591a\u6b21\u5220\u8282\u70b9&#xff0c;\u6210\u5458\u51fd\u6570\u53ef\u4ee5\u4e00\u6b21\u904d\u5386\u5b8c\u6210\u5220\u9664<\/td>\n<td>\u4e00\u6b21\u904d\u5386&#xff0c;\u9047\u5230\u5339\u914d\u8282\u70b9\u76f4\u63a5\u6458\u94fe<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5176\u4e2d list::sort \u7684\u5b9e\u73b0\u975e\u5e38\u7cbe\u5de7&#xff1a;\u5b83\u7ef4\u62a4\u4e00\u4e2a\u957f\u5ea6\u56fa\u5b9a\u7684\u6307\u9488\u6570\u7ec4&#xff0c;\u6bcf\u4e2a\u4f4d\u7f6e\u5bf9\u5e94\u4e00\u6761\u957f\u5ea6\u4e3a 2^i \u7684\u6709\u5e8f\u5b50\u94fe\u8868&#xff0c;\u9010\u4e2a\u628a\u8282\u70b9\u5408\u5e76\u8fdb\u5bf9\u5e94\u5c42\u7ea7&#xff0c;\u6700\u7ec8\u62fc\u63a5\u51fa\u5b8c\u6574\u6709\u5e8f\u94fe\u8868&#xff0c;\u5168\u7a0b\u4e0d\u9700\u8981\u989d\u5916\u6570\u7ec4\u7a7a\u95f4\u3002<\/p>\n<hr \/>\n<h3>\u56db\u3001\u5185\u5b58\u7279\u6027\u4e0e\u6027\u80fd\u771f\u76f8<\/h3>\n<h4>4.1 \u5185\u5b58\u5f00\u9500&#xff1a;\u5c0f\u5143\u7d20\u573a\u666f\u6781\u5176\u6d6a\u8d39<\/h4>\n<p>\u6bcf\u4e2a list \u8282\u70b9\u9664\u4e86\u6570\u636e\u672c\u8eab&#xff0c;\u8fd8\u8981\u643a\u5e26\u4e24\u4e2a\u6307\u9488&#xff1a;<\/p>\n<ul>\n<li>64 \u4f4d\u7cfb\u7edf\u4e0b&#xff0c;\u4e24\u4e2a\u6307\u9488\u5171 16 \u5b57\u8282<\/li>\n<li>\u5982\u679c\u5b58 int&#xff08;4 \u5b57\u8282&#xff09;&#xff0c;\u989d\u5916\u5f00\u9500\u9ad8\u8fbe 300%&#xff0c;\u5185\u5b58\u5229\u7528\u7387\u53ea\u6709 20%<\/li>\n<li>\u5982\u679c\u5b58\u5927\u5bf9\u8c61&#xff08;\u6bd4\u5982\u51e0\u767e\u5b57\u8282\u7684\u7ed3\u6784\u4f53&#xff09;&#xff0c;\u6307\u9488\u5f00\u9500\u53ef\u4ee5\u5ffd\u7565<\/li>\n<\/ul>\n<p>\u540c\u65f6&#xff0c;\u8282\u70b9\u662f\u9010\u4e2a\u5206\u914d\u5728\u5806\u4e0a\u7684&#xff0c;\u6ca1\u6709\u9884\u5206\u914d\u3001\u6ca1\u6709\u5bb9\u91cf\u6982\u5ff5&#xff0c;\u7528\u4e00\u4e2a\u5206\u914d\u4e00\u4e2a&#xff0c;\u4e0d\u5b58\u5728\u6269\u5bb9\u6296\u52a8&#xff0c;\u4f46\u4e5f\u5e26\u6765\u4e86\u5185\u5b58\u788e\u7247\u95ee\u9898\u3002<\/p>\n<h4>4.2 \u7f13\u5b58\u53cb\u597d\u6027&#xff1a;\u51e0\u4e4e\u4e3a\u96f6<\/h4>\n<p>\u8fd9\u662f list \u6700\u81f4\u547d\u7684\u6027\u80fd\u77ed\u677f\u3002\u73b0\u4ee3 CPU \u4f9d\u8d56\u7f13\u5b58\u9884\u53d6\u6765\u52a0\u901f\u8fde\u7eed\u5185\u5b58\u8bbf\u95ee&#xff0c;\u800c list \u7684\u8282\u70b9\u6563\u843d\u5728\u5806\u5185\u5b58\u7684\u5404\u4e2a\u4f4d\u7f6e&#xff0c;\u5730\u5740\u6beb\u65e0\u8fde\u7eed\u6027\u3002<\/p>\n<p>\u904d\u5386 list \u65f6&#xff0c;\u6bcf\u8bbf\u95ee\u4e00\u4e2a\u8282\u70b9\u90fd\u5927\u6982\u7387\u89e6\u53d1\u4e00\u6b21\u7f13\u5b58\u672a\u547d\u4e2d&#xff08;Cache Miss&#xff09;&#xff0c;\u9700\u8981\u4ece\u4e3b\u5b58\u8bfb\u53d6\u6570\u636e&#xff0c;\u8017\u65f6\u662f\u7f13\u5b58\u8bbf\u95ee\u7684\u51e0\u5341\u4e0a\u767e\u500d\u3002\u5f88\u591a\u4eba\u76f4\u89c9\u4e0a\u201c\u94fe\u8868\u63d2\u5220\u5feb\u201d&#xff0c;\u4f46\u5b9e\u9645\u573a\u666f\u4e2d&#xff0c;\u627e\u5230\u63d2\u5165\u4f4d\u7f6e\u7684\u904d\u5386\u5f00\u9500&#xff0c;\u65e9\u5df2\u62b5\u6d88\u4e86\u63d2\u5220\u7684 O(1) \u4f18\u52bf\u3002<\/p>\n<p>\u8fd9\u4e5f\u662f\u4e1a\u754c\u5171\u8bc6&#xff1a;\u9ed8\u8ba4\u4f18\u5148\u7528 vector&#xff0c;\u9664\u975e\u4f60\u80fd\u5b9e\u6d4b\u8bc1\u660e list \u66f4\u5feb\u3002<\/p>\n<h4>4.3 \u8fed\u4ee3\u5668\u5931\u6548\u89c4\u5219\u603b\u7ed3<\/h4>\n<table>\n<tr>\u64cd\u4f5c\u8fed\u4ee3\u5668\/\u5f15\u7528\/\u6307\u9488\u5931\u6548\u60c5\u51b5<\/tr>\n<tbody>\n<tr>\n<td>\u63d2\u5165\u5143\u7d20<\/td>\n<td>\u5168\u90e8\u6709\u6548&#xff0c;\u65e0\u4efb\u4f55\u5931\u6548<\/td>\n<\/tr>\n<tr>\n<td>\u5220\u9664\u5143\u7d20<\/td>\n<td>\u4ec5\u88ab\u5220\u9664\u7684\u8282\u70b9\u5931\u6548&#xff0c;\u5176\u4f59\u5168\u90e8\u6709\u6548<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u662f\u6240\u6709 STL \u5bb9\u5668\u4e2d\u8fed\u4ee3\u5668\u7a33\u5b9a\u6027\u6700\u9ad8\u7684&#xff0c;\u4e5f\u662f\u5f88\u591a\u573a\u666f\u9009\u62e9 list \u7684\u6838\u5fc3\u7406\u7531\u2014\u2014\u4f60\u53ef\u4ee5\u653e\u5fc3\u5730\u6301\u6709\u67d0\u4e2a\u5143\u7d20\u7684\u6307\u9488\u6216\u5f15\u7528&#xff0c;\u4e0d\u7528\u62c5\u5fc3\u5176\u4ed6\u8282\u70b9\u589e\u5220\u5bfc\u81f4\u5b83\u5931\u6548\u3002<\/p>\n<hr \/>\n<h3>\u4e94\u3001\u8bbe\u8ba1\u6743\u8861\u4e0e\u9009\u578b\u5efa\u8bae<\/h3>\n<h4>5.1 list \u7684\u6838\u5fc3\u4f18\u52bf<\/h4>\n<li>\u5df2\u77e5\u4f4d\u7f6e\u4e0b&#xff0c;\u4efb\u610f\u4f4d\u7f6e\u63d2\u5220 O(1)&#xff0c;\u4e0d\u9700\u8981\u79fb\u52a8\u5176\u4ed6\u5143\u7d20<\/li>\n<li>\u8fed\u4ee3\u5668\u3001\u5f15\u7528\u3001\u6307\u9488\u7a33\u5b9a\u6027\u6781\u5f3a&#xff0c;\u63d2\u5165\u4e0d\u5931\u6548&#xff0c;\u5220\u9664\u4ec5\u5931\u6548\u88ab\u5220\u5143\u7d20<\/li>\n<li>\u652f\u6301 splice \u96f6\u62f7\u8d1d\u8282\u70b9\u8f6c\u79fb&#xff0c;\u9002\u5408\u94fe\u8868\u8c03\u5ea6\u7c7b\u573a\u666f<\/li>\n<li>\u65e0\u6269\u5bb9\u6296\u52a8&#xff0c;\u5185\u5b58\u589e\u957f\u5e73\u7a33&#xff0c;\u4e0d\u4f1a\u51fa\u73b0\u5168\u91cf\u62f7\u8d1d\u7684\u6027\u80fd\u5c16\u523a<\/li>\n<h4>5.2 list \u7684\u6838\u5fc3\u52a3\u52bf<\/h4>\n<li>\u4e0d\u652f\u6301\u968f\u673a\u8bbf\u95ee&#xff0c;\u8bbf\u95ee\u7b2c n \u4e2a\u5143\u7d20 O(n)<\/li>\n<li>\u904d\u5386\u6027\u80fd\u6781\u5dee&#xff0c;\u7f13\u5b58\u4e0d\u53cb\u597d&#xff0c;\u5b9e\u9645\u904d\u5386\u901f\u5ea6\u6bd4 vector \u6162\u4e00\u4e2a\u6570\u91cf\u7ea7<\/li>\n<li>\u8282\u70b9\u989d\u5916\u5f00\u9500\u5927&#xff0c;\u5c0f\u5143\u7d20\u573a\u666f\u5185\u5b58\u6d6a\u8d39\u4e25\u91cd<\/li>\n<li>\u67e5\u627e\u5fc5\u987b\u904d\u5386&#xff0c;\u6ca1\u6709\u4efb\u4f55\u5feb\u901f\u5b9a\u4f4d\u624b\u6bb5<\/li>\n<h4>5.3 \u9009\u578b\u539f\u5219<\/h4>\n<ul>\n<li>90% \u7684\u5e38\u89c4\u573a\u666f&#xff0c;\u4f18\u5148\u9009 vector<\/li>\n<li>\u9891\u7e41\u53cc\u7aef\u64cd\u4f5c\u3001\u4e0d\u9700\u8981\u968f\u673a\u8bbf\u95ee&#xff0c;\u9009 deque<\/li>\n<li>\u53ea\u6709\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u65f6&#xff0c;\u624d\u8003\u8651 list&#xff1a;\n<li>\u9891\u7e41\u5728\u4e2d\u95f4\u4f4d\u7f6e\u63d2\u5165\u5220\u9664<\/li>\n<li>\u53ef\u4ee5\u5feb\u901f\u62ff\u5230\u63d2\u5165\u4f4d\u7f6e\u7684\u8fed\u4ee3\u5668&#xff08;\u6bd4\u5982\u914d\u5408\u54c8\u5e0c\u8868\u7d22\u5f15&#xff09;<\/li>\n<li>\u9700\u8981\u4fdd\u8bc1\u5143\u7d20\u5730\u5740\/\u5f15\u7528\u957f\u671f\u7a33\u5b9a&#xff0c;\u4e0d\u80fd\u56e0\u589e\u5220\u5931\u6548<\/li>\n<li>\u9700\u8981\u9891\u7e41\u8fdb\u884c\u8282\u70b9\u62fc\u63a5\u3001\u8f6c\u79fb\u64cd\u4f5c<\/li>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 STL \u987a\u5e8f\u5bb9\u5668\u4e09\u5de8\u5934\u4e2d&#xff0c;list \u662f\u6700\u201c\u7eaf\u7cb9\u201d\u7684\u94fe\u5f0f\u7ed3\u6784\u4ee3\u8868&#xff1a;vector \u4e3b\u6253\u8fde\u7eed\u5185\u5b58\u7684\u6781\u81f4\u8bbf\u95ee\u6548\u7387&#xff0c;deque \u4e3b\u6253\u53cc\u7aef\u64cd\u4f5c\u7684\u6298\u4e2d\u5e73\u8861&#xff0c;list \u5219\u628a\u4efb\u610f\u4f4d\u7f6e\u63d2\u5220\u7684\u80fd\u529b\u62c9\u6ee1&#xff0c;\u4ee3\u4ef7\u662f\u5f7b\u5e95\u653e\u5f03\u968f\u673a\u8bbf\u95ee\u4e0e\u7f13\u5b58\u53cb\u597d\u6027\u3002<br \/>\n\u5b83\u7684\u5e95\u5c42\u662f\u7ecf\u5178\u7684\u53cc\u5411\u5faa\u73af\u94fe\u8868&#xff0c;\u5b9e\u73b0\u770b\u4f3c\u7b80\u5355&#xff0c;\u5b9e\u5219\u85cf\u7740\u5927\u91cf STL \u7684\u8bbe\u8ba1\u5de7\u601d\u2014\u2014\u6bd4\u5982\u54e8\u5175\u8282\u70b9\u3001\u5206\u5c42\u8282\u70b9\u7ed3\u6784\u3001\u4e13\u5c5e\u6210\u5458\u7b97\u6cd5\u7b49\u3002\u672c\u6587\u57fa\u4e8e GCC libstdc \u6e90<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,3027,2640],"topic":[],"class_list":["post-91093","post","type-post","status-publish","format-standard","hentry","category-server","tag-c","tag-list","tag-2640"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++ : list \u6e90\u7801\u7ea7\u6df1\u5ea6\u62c6\u89e3\u2014\u2014\u53cc\u5411\u5faa\u73af\u94fe\u8868\u7684\u4f18\u96c5\u4e0e\u4ee3\u4ef7 - \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\/91093.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ : list \u6e90\u7801\u7ea7\u6df1\u5ea6\u62c6\u89e3\u2014\u2014\u53cc\u5411\u5faa\u73af\u94fe\u8868\u7684\u4f18\u96c5\u4e0e\u4ee3\u4ef7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5728 STL \u987a\u5e8f\u5bb9\u5668\u4e09\u5de8\u5934\u4e2d&#xff0c;list \u662f\u6700\u201c\u7eaf\u7cb9\u201d\u7684\u94fe\u5f0f\u7ed3\u6784\u4ee3\u8868&#xff1a;vector \u4e3b\u6253\u8fde\u7eed\u5185\u5b58\u7684\u6781\u81f4\u8bbf\u95ee\u6548\u7387&#xff0c;deque \u4e3b\u6253\u53cc\u7aef\u64cd\u4f5c\u7684\u6298\u4e2d\u5e73\u8861&#xff0c;list \u5219\u628a\u4efb\u610f\u4f4d\u7f6e\u63d2\u5220\u7684\u80fd\u529b\u62c9\u6ee1&#xff0c;\u4ee3\u4ef7\u662f\u5f7b\u5e95\u653e\u5f03\u968f\u673a\u8bbf\u95ee\u4e0e\u7f13\u5b58\u53cb\u597d\u6027\u3002 \u5b83\u7684\u5e95\u5c42\u662f\u7ecf\u5178\u7684\u53cc\u5411\u5faa\u73af\u94fe\u8868&#xff0c;\u5b9e\u73b0\u770b\u4f3c\u7b80\u5355&#xff0c;\u5b9e\u5219\u85cf\u7740\u5927\u91cf STL \u7684\u8bbe\u8ba1\u5de7\u601d\u2014\u2014\u6bd4\u5982\u54e8\u5175\u8282\u70b9\u3001\u5206\u5c42\u8282\u70b9\u7ed3\u6784\u3001\u4e13\u5c5e\u6210\u5458\u7b97\u6cd5\u7b49\u3002\u672c\u6587\u57fa\u4e8e GCC libstdc \u6e90\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/91093.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-06T13:08:41+00:00\" \/>\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=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/91093.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/91093.html\",\"name\":\"C++ : list \u6e90\u7801\u7ea7\u6df1\u5ea6\u62c6\u89e3\u2014\u2014\u53cc\u5411\u5faa\u73af\u94fe\u8868\u7684\u4f18\u96c5\u4e0e\u4ee3\u4ef7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-06T13:08:41+00:00\",\"dateModified\":\"2026-08-06T13:08:41+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/91093.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/91093.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/91093.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ : list \u6e90\u7801\u7ea7\u6df1\u5ea6\u62c6\u89e3\u2014\u2014\u53cc\u5411\u5faa\u73af\u94fe\u8868\u7684\u4f18\u96c5\u4e0e\u4ee3\u4ef7\"}]},{\"@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++ : list \u6e90\u7801\u7ea7\u6df1\u5ea6\u62c6\u89e3\u2014\u2014\u53cc\u5411\u5faa\u73af\u94fe\u8868\u7684\u4f18\u96c5\u4e0e\u4ee3\u4ef7 - \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\/91093.html","og_locale":"zh_CN","og_type":"article","og_title":"C++ : list \u6e90\u7801\u7ea7\u6df1\u5ea6\u62c6\u89e3\u2014\u2014\u53cc\u5411\u5faa\u73af\u94fe\u8868\u7684\u4f18\u96c5\u4e0e\u4ee3\u4ef7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5728 STL \u987a\u5e8f\u5bb9\u5668\u4e09\u5de8\u5934\u4e2d&#xff0c;list \u662f\u6700\u201c\u7eaf\u7cb9\u201d\u7684\u94fe\u5f0f\u7ed3\u6784\u4ee3\u8868&#xff1a;vector \u4e3b\u6253\u8fde\u7eed\u5185\u5b58\u7684\u6781\u81f4\u8bbf\u95ee\u6548\u7387&#xff0c;deque \u4e3b\u6253\u53cc\u7aef\u64cd\u4f5c\u7684\u6298\u4e2d\u5e73\u8861&#xff0c;list \u5219\u628a\u4efb\u610f\u4f4d\u7f6e\u63d2\u5220\u7684\u80fd\u529b\u62c9\u6ee1&#xff0c;\u4ee3\u4ef7\u662f\u5f7b\u5e95\u653e\u5f03\u968f\u673a\u8bbf\u95ee\u4e0e\u7f13\u5b58\u53cb\u597d\u6027\u3002 \u5b83\u7684\u5e95\u5c42\u662f\u7ecf\u5178\u7684\u53cc\u5411\u5faa\u73af\u94fe\u8868&#xff0c;\u5b9e\u73b0\u770b\u4f3c\u7b80\u5355&#xff0c;\u5b9e\u5219\u85cf\u7740\u5927\u91cf STL \u7684\u8bbe\u8ba1\u5de7\u601d\u2014\u2014\u6bd4\u5982\u54e8\u5175\u8282\u70b9\u3001\u5206\u5c42\u8282\u70b9\u7ed3\u6784\u3001\u4e13\u5c5e\u6210\u5458\u7b97\u6cd5\u7b49\u3002\u672c\u6587\u57fa\u4e8e GCC libstdc \u6e90","og_url":"https:\/\/www.wsisp.com\/helps\/91093.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-06T13:08:41+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/91093.html","url":"https:\/\/www.wsisp.com\/helps\/91093.html","name":"C++ : list \u6e90\u7801\u7ea7\u6df1\u5ea6\u62c6\u89e3\u2014\u2014\u53cc\u5411\u5faa\u73af\u94fe\u8868\u7684\u4f18\u96c5\u4e0e\u4ee3\u4ef7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-06T13:08:41+00:00","dateModified":"2026-08-06T13:08:41+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/91093.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/91093.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/91093.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++ : list \u6e90\u7801\u7ea7\u6df1\u5ea6\u62c6\u89e3\u2014\u2014\u53cc\u5411\u5faa\u73af\u94fe\u8868\u7684\u4f18\u96c5\u4e0e\u4ee3\u4ef7"}]},{"@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\/91093","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=91093"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/91093\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=91093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=91093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=91093"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=91093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}