{"id":35365,"date":"2025-05-04T13:49:49","date_gmt":"2025-05-04T05:49:49","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/35365.html"},"modified":"2025-05-04T13:49:49","modified_gmt":"2025-05-04T05:49:49","slug":"list%e7%9a%84%e6%a8%a1%e6%8b%9f%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/35365.html","title":{"rendered":"list\u7684\u6a21\u62df\u5b9e\u73b0"},"content":{"rendered":"<h2>\u4e00.list\u7684\u7b80\u5355\u4ecb\u7ecd<\/h2>\n<p>list\u662f\u4e00\u4e2a\u5e26\u5934\u53cc\u5411\u5faa\u73af\u7684\u94fe\u8868&#xff0c;\u901a\u8fc7\u5934\u7ed3\u70b9\u5206\u9694\u5f00\u9996\u672b\u5c3e\u3002\u5b83\u548cvector\u7684\u4f7f\u7528\u65b9\u6cd5\u7c7b\u4f3c&#xff0c;\u53ef\u4ee5\u8fdb\u884c\u5934\u63d2\u5c3e\u63d2&#xff0c;&#043;&#043;\/&#8211;\u7b49\u64cd\u4f5c&#xff0c;\u533a\u522b\u5728\u4e8elist\u7684\u7ed3\u70b9\u5728\u5185\u5b58\u4e0a\u4e0d\u662f\u8fde\u7eed\u7684\u3002list\u5c5e\u4e8e\u53cc\u5411\u8fed\u4ee3\u5668\u5373\u53ef\u4ee5&#043;&#043;\/&#8211;&#xff0c;\u4e0d\u80fd\u60f3vector\u4e00\u6837\u53ef\u4ee5\u8fdb\u884c\u968f\u673a\u8bbf\u95ee\u3002<\/p>\n<h2>\u4e8c.list\u6a21\u62df\u5b9e\u73b0\u7684\u4e09\u4e2a\u7c7b<\/h2>\n<h3>1.\u7ed3\u70b9\u7c7b<\/h3>\n<p>\u6839\u636elist\u7684\u7279\u70b9\u5e26\u5934\u53cc\u5411\u5faa\u73af&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5f97\u77e5&#xff0c;\u4ed6\u9700\u8981\u4e00\u4e2a\u524d\u7f6e\u7ed3\u70b9prev&#xff0c;\u4ee5\u53ca\u540e\u7f6e\u7ed3\u70b9next&#xff0c;\u4fdd\u8bc1\u80fd\u5411\u524d\u5411\u540e\u627e\u5230\u7ed3\u70b9\u3002 \u6bcf\u4e2a\u7ed3\u70b9\u5b58\u6709\u6570\u636edata&#xff0c;\u6211\u4eec\u53ef\u4ee5\u7528\u6a21\u677fT\u6765\u8fdb\u884c\u590d\u7528\u3002<\/p>\n<p> template &lt;class T&gt;<br \/>\nstruct list_node<br \/>\n{<br \/>\nlist_node(const T&amp; x &#061; T())\/\/\u6a21\u677f\u6709x\u65f6\u60c5\u51b5<br \/>\n:_next(nullptr)<br \/>\n,_prev(nullptr)<br \/>\n,_data(x)<br \/>\n{}<\/p>\n<p>list_node&lt;T&gt;* _next;<br \/>\nlist_node&lt;T&gt;* _prev;<br \/>\nT _data;<br \/>\n}; <\/p>\n<h3>\u00a02.\u8fed\u4ee3\u5668\u7c7b<\/h3>\n<p>\u6211\u4eec\u77e5\u9053\u8fed\u4ee3\u5668\u5206\u4e3a\u666e\u901a\u8fed\u4ee3\u5668\u548cconst\u8fed\u4ee3\u5668&#xff0c;\u5728\u5b9e\u73b0string\u7c7b\u548cvector\u7c7b\u65f6\u6211\u4eec\u5e76\u6ca1\u6709\u5355\u72ec\u5bf9\u8fed\u4ee3\u5668\u8fd9\u4e00\u7c7b\u8fdb\u884c\u5b9e\u73b0&#xff0c;\u8fd9\u662f\u56e0\u4e3avector\u548cstring\u7c7b\u5728\u5e95\u5c42\u7a7a\u95f4\u4e0a\u662f\u8fde\u7eed\u7684&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u8fdb\u884c&#043;&#043;\/&#8211;&#xff0c;\u89e3\u5f15\u7528\u64cd\u4f5c\u3002\u4f46list\u5728\u5e95\u5c42\u4e2d\u662f\u7531\u6307\u9488\u6765\u8fde\u63a5\u7684&#xff0c;\u6240\u4ee5\u76f4\u63a5&#043;&#043;\/&#8211;\u89e3\u5f15\u7528\u65e0\u6cd5\u5b9e\u73b0\u6211\u4eec\u60f3\u8981\u7684\u6548\u679c\u3002\u6240\u4ee5\u6211\u4eec\u8981\u5355\u72ec\u63d0\u51fa\u8fed\u4ee3\u5668\u5bf9&#043;&#043;\/&#8211;\u89e3\u5f15\u7528\u8fdb\u884c\u91cd\u8f7d\u8fd0\u7b97\u7b26\u64cd\u4f5c\u3002<\/p>\n<p> template&lt;class T, class Ref, class Ptr&gt;<br \/>\nstruct list_iterator<br \/>\n{<br \/>\ntypedef list_node&lt;T&gt; Node;<br \/>\ntypedef list_iterator&lt;T, Ref, Ptr&gt; Self;<br \/>\nNode* _node;<\/p>\n<p>list_iterator(Node* node)<br \/>\n:_node(node)<br \/>\n{}<\/p>\n<p>T&amp; operator*()<br \/>\n{<br \/>\nreturn _node-&gt;_data;<br \/>\n}<\/p>\n<p>T&amp; operator&#043;&#043;()\/\/\u524d\u7f6e<br \/>\n{<br \/>\n_node &#061; _node-&gt;_next;<br \/>\nreturn *this;<br \/>\n}<\/p>\n<p>T&amp; operator&#043;&#043;(int)\/\/\u540e\u7f6e,\u540e\u7f6e&#043;&#043;\u533a\u5206\u524d\u7f6e\u8981\u52a0\u5165\u62ec\u53f7<br \/>\n{<br \/>\nSelf tmp(*this);<br \/>\n_node &#061; _node-&gt;_next;<br \/>\nreturn tmp;<br \/>\n}<\/p>\n<p>T&amp; operator&#8211;()\/\/\u524d\u7f6e<br \/>\n{<br \/>\n_node &#061; _node-&gt;_prev;<br \/>\nreturn *this;<br \/>\n}<\/p>\n<p>T&amp; operator&#8211;(int)\/\/\u524d\u7f6e<br \/>\n{<br \/>\nSelf tmp(*this);<br \/>\n_node &#061; _node-&gt;_prev;<br \/>\nreturn tmp;<br \/>\n}<\/p>\n<p>T* operator-&gt;()<br \/>\n{<br \/>\nreturn &amp;_node-&gt;_data;<br \/>\n}<\/p>\n<p>bool operator!&#061;(const T&amp; it)<br \/>\n{<br \/>\nreturn _node !&#061; it._node;<br \/>\n}<\/p>\n<p>bool operator&#061;&#061;(const T&amp; it)<br \/>\n{<br \/>\nreturn _node &#061;&#061; _it._node;<br \/>\n}<br \/>\n}; <\/p>\n<p>\u5982\u4e0a\u6211\u4eec\u5bf9\u8fed\u4ee3\u5668\u8fdb\u884c\u4e86\u521d\u6b65\u7684\u5b9e\u73b0&#xff0c;\u91cc\u9762\u7684\u5b9e\u73b0\u5185\u5bb9\u8f83\u4e3a\u7b80\u5355\u5c31\u4e0d\u4e00\u4e00\u5c55\u5f00\u53d9\u8ff0\u3002\u8fd9\u65f6\u5019\u53c8\u6709\u4e86\u53e6\u4e00\u4e2a\u95ee\u9898&#xff0c;\u5982\u679c\u8fed\u4ee3\u5668\u662fconst\u7c7b\u578b\u7684\u8be5\u600e\u4e48\u529e\u5462&#xff1f;\u8fd8\u662f\u50cf\u4e0a\u9762\u8fd9\u6837&#xff0c;\u91cd\u65b0\u5c01\u88c5\u4e00\u4e2aconst_iterator\u7c7b\u5417&#xff1f;<\/p>\n<p>\u8fd9\u6837\u64cd\u4f5c\u56fa\u7136\u662f\u6ca1\u6709\u95ee\u9898\u7684&#xff0c;\u4f46\u662f\u8fd8\u4e0d\u591f\u7b80\u7565\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4ed4\u7ec6\u60f3\u60f3&#xff0c;\u666e\u901a\u8fed\u4ee3\u5668\u4e0econst\u8fed\u4ee3\u5668\u7684\u533a\u522b\u4e0d\u5c31\u662f\u591a\u4e86\u4e00\u4e2aconst\u5417&#xff1f;\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u7528\u6a21\u677f\u6765\u5957\u7528\u5b9e\u73b0\u3002<\/p>\n<p> template&lt;class T,class Ref,class Ptr&gt;\/\/\u63d0\u4f9b\u6a21\u677f\u53c2\u6570&#xff0c;\u4e3aconst\u7c7b\u578b\u63d0\u4f9b\u6a21\u677f\u53c2\u6570,ref\u4ee3\u66ff\u5f15\u7528&#xff0c;ptr\u4ee3\u66ff*&#xff0c;\u590d\u7528<br \/>\nstruct list_iterator<br \/>\n{<br \/>\ntypedef list_node&lt;T&gt; Node;<br \/>\ntypedef list_iterator&lt;T, Ref, Ptr&gt; Self;<br \/>\nNode* _node;<\/p>\n<p>list_iterator(Node* node)<br \/>\n:_node(node)<br \/>\n{}<\/p>\n<p>Ref operator*()<br \/>\n{<br \/>\nreturn _node-&gt;_data;<br \/>\n}<\/p>\n<p>Self&amp; operator&#043;&#043;()\/\/\u524d\u7f6e<br \/>\n{<br \/>\n_node &#061; _node-&gt;_next;<br \/>\nreturn *this;<br \/>\n}<\/p>\n<p>Self operator&#043;&#043;(int)\/\/\u540e\u7f6e,\u540e\u7f6e&#043;&#043;\u533a\u5206\u524d\u7f6e\u8981\u52a0\u5165\u62ec\u53f7<br \/>\n{<br \/>\nSelf tmp(*this);<br \/>\n_node &#061; _node-&gt;_next;<br \/>\nreturn tmp;<br \/>\n}<\/p>\n<p>Self&amp; operator&#8211;()\/\/\u524d\u7f6e<br \/>\n{<br \/>\n_node &#061; _node-&gt;_prev;<br \/>\nreturn *this;<br \/>\n}<\/p>\n<p>Self operator&#8211;(int)\/\/\u524d\u7f6e<br \/>\n{<br \/>\nSelf tmp(*this);<br \/>\n_node &#061; _node-&gt;_prev;<br \/>\nreturn tmp;<br \/>\n}<\/p>\n<p>Ptr operator-&gt;()<br \/>\n{<br \/>\nreturn &amp;_node-&gt;_data;<br \/>\n}<\/p>\n<p>bool operator!&#061;(const Self&amp; it)<br \/>\n{<br \/>\nreturn _node !&#061; it._node;<br \/>\n}<\/p>\n<p>bool operator&#061;&#061;(const Self&amp; it)<br \/>\n{<br \/>\nreturn _node &#061;&#061; _it._node;<br \/>\n}<br \/>\n}; <\/p>\n<p>\u6211\u4eec\u5c06\u539f\u5148\u7684T&amp;\u00a0 \u7528\u6a21\u677fRef\u6765\u66ff\u4ee3&#xff0c;T*\u00a0 \u7528\u6a21\u677fPtr\u6765\u4ee3\u66ff\u3002\u8fd9\u6837\u5c31\u5bf9\u4ee3\u7801\u8fdb\u884c\u4e86\u7f29\u51cf\u3002\u6240\u4ee5\u7528ref\u548cptr\u6a21\u677f\u6211\u4eec\u5c31\u4e0d\u9700\u8981\u5173\u5fc3\u662f\u4e0d\u662fconst\u7c7b\u578b\u8fed\u4ee3\u5668&#xff0c;\u53ea\u8981\u4f20\u5c31\u662f\u4ec0\u4e48&#xff0c;\u6211\u4eec\u5c31\u65e0\u9700\u5173\u5fc3\u3002\u00a0<\/p>\n<h3>3.\u94fe\u8868\u7c7b<\/h3>\n<p> template &lt;class T&gt;<br \/>\nclass list<br \/>\n{<br \/>\ntypedef list_node&lt;T&gt; Node;<br \/>\npublic:<br \/>\ntypedef list_iterator&lt;T,T&amp;,T*&gt; iterator;<br \/>\ntypedef list_iterator&lt;T, const T&amp;, const T*&gt; const_iterator;<\/p>\n<p>iterator begin()<br \/>\n{<br \/>\nreturn list_iterator(_head-&gt;_next);<br \/>\n}<\/p>\n<p>iterator end()<br \/>\n{<br \/>\nreturn list_iterator(_head);<br \/>\n}<\/p>\n<p>void empty_init()<br \/>\n{<br \/>\n_head &#061; new Node;<br \/>\n_head-&gt;_prev &#061; _head;<br \/>\n_head-&gt;_next &#061; _head;<br \/>\n}<\/p>\n<p>list()<br \/>\n{<br \/>\nempty_init();<br \/>\n}<\/p>\n<p>list(initializer_list&lt;T&gt; it)<br \/>\n{<br \/>\nfor (auto&amp; e : it)<br \/>\n{<br \/>\npush_back(e);<br \/>\n}<br \/>\n}<\/p>\n<p>list(const list&lt;T&gt;&amp; it)<br \/>\n{<br \/>\nempty_init();<br \/>\nfor (auto&amp; e : it)<br \/>\n{<br \/>\npush_back(e);<br \/>\n}<br \/>\n}<\/p>\n<p>~list()<br \/>\n{<br \/>\nclear();<br \/>\n}<\/p>\n<p>void swap(list&lt;T&gt;&amp; it)<br \/>\n{<br \/>\nstd::swap(_head, it._head);<br \/>\n}<\/p>\n<p>list&lt;T&gt;&amp; operator&#061;(list&lt;T&gt; it)<br \/>\n{<br \/>\nswap(it);<br \/>\nreturn *this;<br \/>\n}<\/p>\n<p>void clear()<br \/>\n{<br \/>\niterator it &#061; begin();<br \/>\nwhile (it !&#061; end())<br \/>\n{<br \/>\nit &#061; erase(it);<br \/>\n}<br \/>\n}<\/p>\n<p>void push_back(const T&amp; x)<br \/>\n{<br \/>\nNode* newnode &#061; new Node(x);<\/p>\n<p>Node* tail &#061; _head-&gt;_prev;<br \/>\nnewnode-&gt;_prev &#061; tail;<br \/>\ntail-&gt;_next &#061; newnode;<br \/>\nnewnode-&gt;_next &#061; _head;<br \/>\n_head-&gt;_prev &#061; newnode;<br \/>\n}<\/p>\n<p>void push_front(const T&amp; x)<br \/>\n{<br \/>\ninsert(begin(), x);<br \/>\n}<\/p>\n<p>void push_back(const T&amp; x)<br \/>\n{<br \/>\ninsert(end(), x);<br \/>\n}<\/p>\n<p>void pop_front()<br \/>\n{<br \/>\nerase(begin());<br \/>\n}<\/p>\n<p>void pop_back()<br \/>\n{<br \/>\nerase(&#8211;end());<br \/>\n}<\/p>\n<p>void insert(iterator pos, const T&amp; x)<br \/>\n{<br \/>\nNode* cur &#061; pos._node;<br \/>\nNode* prev &#061; cur-&gt;_prev;<br \/>\nNode* newnode &#061; new Node(x);<br \/>\nprev-&gt;_next &#061; newnode;<br \/>\nnewnode-&gt;_prev &#061; prev;<br \/>\ncur-&gt;_prev &#061; newnode;<br \/>\nnewnode-&gt;_next &#061; cur;<br \/>\n}<\/p>\n<p>iterator erase(iterator pos)<br \/>\n{<br \/>\nassert(pos !&#061; end());<br \/>\nNode* cur &#061; pos._node;<br \/>\nNode* nextNode &#061; cur-&gt;_next;<br \/>\nNode* prevNode &#061; cur-&gt;_prev;<\/p>\n<p>prevNode-&gt;_next &#061; nextNode;<br \/>\nnextNode-&gt;_prev &#061; prevNode;<\/p>\n<p>delete cur;<br \/>\nreturn iterator(nextNode);<br \/>\n}<\/p>\n<p>private:<br \/>\nNode* _head;<br \/>\n};<br \/>\n}<\/p>\n<p>\u4e0a\u8ff0\u53ea\u9700\u8981\u6ce8\u610f\u4e00\u70b9&#xff0c;\u5c31\u662ferase\u7684\u7528\u6cd5\u3002erase\u5728\u5b98\u65b9\u5e93\u4e2d\u662f\u6709\u8fd4\u56de\u503c\u7684&#xff0c;\u5728\u4f7f\u7528\u65f6&#xff0c;\u4f8b\u5982\u6790\u6784\u65f6\u9700\u8981\u7528\u53d8\u91cf\u6765\u63a5\u6536erase\u7684\u8fd4\u56de\u503c&#xff0c;\u5426\u5219\u5bb9\u6613\u5bfc\u81f4\u8fed\u4ee3\u5668\u5931\u6548\u3002<\/p>\n<p>\u94fe\u8868\u90e8\u5206\u7684\u5b9e\u73b0\u4e0d\u96be&#xff0c;\u57fa\u672c\u90fd\u662f\u5148\u524dvector\u7c7b\u5b9e\u73b0\u7684\u529f\u80fd\u76f8\u5dee\u65e0\u51e0&#xff0c;\u6784\u9020\u51fd\u6570&#xff0c;\u62f7\u8d1d\u51fd\u6570&#xff0c;\u6790\u6784\u51fd\u6570&#xff0c;\u8fed\u4ee3\u5668\u7684\u8fd0\u7528&#xff0c;\u4ee5\u53ca\u589e\u5220\u7b49\u64cd\u4f5c\u3002<\/p>\n<h2>\u00a0\u4e09.\u603b\u7ed3<\/h2>\n<p>\u672c\u7bc7\u6587\u7ae0\u6700\u5173\u952e\u7684\u5185\u5bb9\u5c31\u662f\u5bf9\u4e8e\u6a21\u677f\u7684\u590d\u7528&#xff0c;\u5728\u9762\u5bf9\u4ee3\u7801\u76f8\u4f3c\u5ea6\u8f83\u9ad8&#xff0c;\u5b9e\u73b0\u529f\u80fd\u7c7b\u4f3c\u7684\u60c5\u51b5\u4e0b&#xff0c;\u6211\u4eec\u9700\u8981\u4f18\u5148\u8003\u8651\u6a21\u677f\u7684\u590d\u7528\u3002<\/p>\n<p>\u4e0b\u9762\u653e\u4e0a\u5b8c\u6574\u4ee3\u7801&#xff1a;<\/p>\n<p>#pragma once<br \/>\n#include &lt;iostream&gt;<br \/>\nusing namespace std;<\/p>\n<p>namespace wu<br \/>\n{<br \/>\ntemplate &lt;class T&gt;<br \/>\nstruct list_node<br \/>\n{<br \/>\nlist_node(const T&amp; x &#061; T())\/\/\u6a21\u677f\u6709x\u65f6\u60c5\u51b5<br \/>\n:_next(nullptr)<br \/>\n,_prev(nullptr)<br \/>\n,_data(x)<br \/>\n{}<\/p>\n<p>list_node&lt;T&gt;* _next;<br \/>\nlist_node&lt;T&gt;* _prev;<br \/>\nT _data;<br \/>\n};<\/p>\n<p>template&lt;class T,class Ref,class Ptr&gt;\/\/\u63d0\u4f9b\u6a21\u677f\u53c2\u6570&#xff0c;\u4e3aconst\u7c7b\u578b\u63d0\u4f9b\u6a21\u677f\u53c2\u6570,ref\u4ee3\u66ff\u5f15\u7528&#xff0c;ptr\u4ee3\u66ff*&#xff0c;\u590d\u7528<br \/>\nstruct list_iterator<br \/>\n{<br \/>\ntypedef list_node&lt;T&gt; Node;<br \/>\ntypedef list_iterator&lt;T, Ref, Ptr&gt; Self;<br \/>\nNode* _node;<\/p>\n<p>list_iterator(Node* node)<br \/>\n:_node(node)<br \/>\n{}<\/p>\n<p>Ref operator*()<br \/>\n{<br \/>\nreturn _node-&gt;_data;<br \/>\n}<\/p>\n<p>Self&amp; operator&#043;&#043;()\/\/\u524d\u7f6e<br \/>\n{<br \/>\n_node &#061; _node-&gt;_next;<br \/>\nreturn *this;<br \/>\n}<\/p>\n<p>Self operator&#043;&#043;(int)\/\/\u540e\u7f6e,\u540e\u7f6e&#043;&#043;\u533a\u5206\u524d\u7f6e\u8981\u52a0\u5165\u62ec\u53f7<br \/>\n{<br \/>\nSelf tmp(*this);<br \/>\n_node &#061; _node-&gt;_next;<br \/>\nreturn tmp;<br \/>\n}<\/p>\n<p>Self&amp; operator&#8211;()\/\/\u524d\u7f6e<br \/>\n{<br \/>\n_node &#061; _node-&gt;_prev;<br \/>\nreturn *this;<br \/>\n}<\/p>\n<p>Self operator&#8211;(int)\/\/\u524d\u7f6e<br \/>\n{<br \/>\nSelf tmp(*this);<br \/>\n_node &#061; _node-&gt;_prev;<br \/>\nreturn tmp;<br \/>\n}<\/p>\n<p>Ptr operator-&gt;()<br \/>\n{<br \/>\nreturn &amp;_node-&gt;_data;<br \/>\n}<\/p>\n<p>bool operator!&#061;(const Self&amp; it)<br \/>\n{<br \/>\nreturn _node !&#061; it._node;<br \/>\n}<\/p>\n<p>bool operator&#061;&#061;(const Self&amp; it)<br \/>\n{<br \/>\nreturn _node &#061;&#061; _it._node;<br \/>\n}<br \/>\n};<\/p>\n<p>template &lt;class T&gt;<br \/>\nclass list<br \/>\n{<br \/>\ntypedef list_node&lt;T&gt; Node;<br \/>\npublic:<br \/>\ntypedef list_iterator&lt;T,T&amp;,T*&gt; iterator;<br \/>\ntypedef list_iterator&lt;T, const T&amp;, const T*&gt; const_iterator;<\/p>\n<p>iterator begin()<br \/>\n{<br \/>\nreturn list_iterator(_head-&gt;_next);<br \/>\n}<\/p>\n<p>iterator end()<br \/>\n{<br \/>\nreturn list_iterator(_head);<br \/>\n}<\/p>\n<p>void empty_init()<br \/>\n{<br \/>\n_head &#061; new Node;<br \/>\n_head-&gt;_prev &#061; _head;<br \/>\n_head-&gt;_next &#061; _head;<br \/>\n}<\/p>\n<p>list()<br \/>\n{<br \/>\nempty_init();<br \/>\n}<\/p>\n<p>list(initializer_list&lt;T&gt; it)<br \/>\n{<br \/>\nfor (auto&amp; e : it)<br \/>\n{<br \/>\npush_back(e);<br \/>\n}<br \/>\n}<\/p>\n<p>list(const list&lt;T&gt;&amp; it)<br \/>\n{<br \/>\nempty_init();<br \/>\nfor (auto&amp; e : it)<br \/>\n{<br \/>\npush_back(e);<br \/>\n}<br \/>\n}<\/p>\n<p>~list()<br \/>\n{<br \/>\nclear();<br \/>\n}<\/p>\n<p>void swap(list&lt;T&gt;&amp; it)<br \/>\n{<br \/>\nstd::swap(_head, it._head);<br \/>\n}<\/p>\n<p>list&lt;T&gt;&amp; operator&#061;(list&lt;T&gt; it)<br \/>\n{<br \/>\nswap(it);<br \/>\nreturn *this;<br \/>\n}<\/p>\n<p>void clear()<br \/>\n{<br \/>\niterator it &#061; begin();<br \/>\nwhile (it !&#061; end())<br \/>\n{<br \/>\nit &#061; erase(it);<br \/>\n}<br \/>\n}<\/p>\n<p>void push_back(const T&amp; x)<br \/>\n{<br \/>\nNode* newnode &#061; new Node(x);<\/p>\n<p>Node* tail &#061; _head-&gt;_prev;<br \/>\nnewnode-&gt;_prev &#061; tail;<br \/>\ntail-&gt;_next &#061; newnode;<br \/>\nnewnode-&gt;_next &#061; _head;<br \/>\n_head-&gt;_prev &#061; newnode;<br \/>\n}<\/p>\n<p>void push_front(const T&amp; x)<br \/>\n{<br \/>\ninsert(begin(), x);<br \/>\n}<\/p>\n<p>void push_back(const T&amp; x)<br \/>\n{<br \/>\ninsert(end(), x);<br \/>\n}<\/p>\n<p>void pop_front()<br \/>\n{<br \/>\nerase(begin());<br \/>\n}<\/p>\n<p>void pop_back()<br \/>\n{<br \/>\nerase(&#8211;end());<br \/>\n}<\/p>\n<p>void insert(iterator pos, const T&amp; x)<br \/>\n{<br \/>\nNode* cur &#061; pos._node;<br \/>\nNode* prev &#061; cur-&gt;_prev;<br \/>\nNode* newnode &#061; new Node(x);<br \/>\nprev-&gt;_next &#061; newnode;<br \/>\nnewnode-&gt;_prev &#061; prev;<br \/>\ncur-&gt;_prev &#061; newnode;<br \/>\nnewnode-&gt;_next &#061; cur;<br \/>\n}<\/p>\n<p>iterator erase(iterator pos)<br \/>\n{<br \/>\nassert(pos !&#061; end());<br \/>\nNode* cur &#061; pos._node;<br \/>\nNode* nextNode &#061; cur-&gt;_next;<br \/>\nNode* prevNode &#061; cur-&gt;_prev;<\/p>\n<p>prevNode-&gt;_next &#061; nextNode;<br \/>\nnextNode-&gt;_prev &#061; prevNode;<\/p>\n<p>delete cur;<br \/>\nreturn iterator(nextNode);<br \/>\n}<\/p>\n<p>private:<br \/>\nNode* _head;<br \/>\n};<br \/>\n} <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.3k\u6b21\uff0c\u70b9\u8d5e65\u6b21\uff0c\u6536\u85cf54\u6b21\u3002\u672c\u7bc7\u6587\u7ae0\u6700\u5173\u952e\u7684\u5185\u5bb9\u5c31\u662f\u5bf9\u4e8e\u6a21\u677f\u7684\u590d\u7528\uff0c\u5728\u9762\u5bf9\u4ee3\u7801\u76f8\u4f3c\u5ea6\u8f83\u9ad8\uff0c\u5b9e\u73b0\u529f\u80fd\u7c7b\u4f3c\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u4f18\u5148\u8003\u8651\u6a21\u677f\u7684\u590d\u7528\u3002list_node(const T&amp; x = T())\/\/\u6a21\u677f\u6709x\u65f6\u60c5\u51b5,_data(x){}T _data;template\/\/\u63d0\u4f9b\u6a21\u677f\u53c2\u6570\uff0c\u4e3aconst\u7c7b\u578b\u63d0\u4f9b\u6a21\u677f\u53c2\u6570,ref\u4ee3\u66ff\u5f15\u7528\uff0cptr\u4ee3\u66ff*\uff0c\u590d\u7528{}Self&amp; operator++()\/\/\u524d\u7f6e\u3002<\/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":[3027,1813],"topic":[],"class_list":["post-35365","post","type-post","status-publish","format-standard","hentry","category-server","tag-list","tag-1813"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>list\u7684\u6a21\u62df\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/35365.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"list\u7684\u6a21\u62df\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.3k\u6b21\uff0c\u70b9\u8d5e65\u6b21\uff0c\u6536\u85cf54\u6b21\u3002\u672c\u7bc7\u6587\u7ae0\u6700\u5173\u952e\u7684\u5185\u5bb9\u5c31\u662f\u5bf9\u4e8e\u6a21\u677f\u7684\u590d\u7528\uff0c\u5728\u9762\u5bf9\u4ee3\u7801\u76f8\u4f3c\u5ea6\u8f83\u9ad8\uff0c\u5b9e\u73b0\u529f\u80fd\u7c7b\u4f3c\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u4f18\u5148\u8003\u8651\u6a21\u677f\u7684\u590d\u7528\u3002list_node(const T&amp; x = T())\/\/\u6a21\u677f\u6709x\u65f6\u60c5\u51b5,_data(x){}T _data;template\/\/\u63d0\u4f9b\u6a21\u677f\u53c2\u6570\uff0c\u4e3aconst\u7c7b\u578b\u63d0\u4f9b\u6a21\u677f\u53c2\u6570,ref\u4ee3\u66ff\u5f15\u7528\uff0cptr\u4ee3\u66ff*\uff0c\u590d\u7528{}Self&amp; operator++()\/\/\u524d\u7f6e\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/35365.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-04T05:49:49+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=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35365.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/35365.html\",\"name\":\"list\u7684\u6a21\u62df\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-04T05:49:49+00:00\",\"dateModified\":\"2025-05-04T05:49:49+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/35365.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/35365.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35365.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"list\u7684\u6a21\u62df\u5b9e\u73b0\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"list\u7684\u6a21\u62df\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/35365.html","og_locale":"zh_CN","og_type":"article","og_title":"list\u7684\u6a21\u62df\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.3k\u6b21\uff0c\u70b9\u8d5e65\u6b21\uff0c\u6536\u85cf54\u6b21\u3002\u672c\u7bc7\u6587\u7ae0\u6700\u5173\u952e\u7684\u5185\u5bb9\u5c31\u662f\u5bf9\u4e8e\u6a21\u677f\u7684\u590d\u7528\uff0c\u5728\u9762\u5bf9\u4ee3\u7801\u76f8\u4f3c\u5ea6\u8f83\u9ad8\uff0c\u5b9e\u73b0\u529f\u80fd\u7c7b\u4f3c\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u4f18\u5148\u8003\u8651\u6a21\u677f\u7684\u590d\u7528\u3002list_node(const T&amp; x = T())\/\/\u6a21\u677f\u6709x\u65f6\u60c5\u51b5,_data(x){}T _data;template\/\/\u63d0\u4f9b\u6a21\u677f\u53c2\u6570\uff0c\u4e3aconst\u7c7b\u578b\u63d0\u4f9b\u6a21\u677f\u53c2\u6570,ref\u4ee3\u66ff\u5f15\u7528\uff0cptr\u4ee3\u66ff*\uff0c\u590d\u7528{}Self&amp; operator++()\/\/\u524d\u7f6e\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/35365.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-04T05:49:49+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/35365.html","url":"https:\/\/www.wsisp.com\/helps\/35365.html","name":"list\u7684\u6a21\u62df\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-04T05:49:49+00:00","dateModified":"2025-05-04T05:49:49+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/35365.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/35365.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/35365.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"list\u7684\u6a21\u62df\u5b9e\u73b0"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/35365","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=35365"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/35365\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=35365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=35365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=35365"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=35365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}