{"id":1377,"date":"2022-07-28T10:45:20","date_gmt":"2022-07-28T02:45:20","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=1377"},"modified":"2022-07-28T10:45:20","modified_gmt":"2022-07-28T02:45:20","slug":"%e6%9f%a0%e6%aa%ac%e5%be%ae%e8%b6%a3%e7%ac%94%e8%af%95%e9%a2%98-%e5%8f%8d%e8%bd%ac%e5%8d%95%e9%93%be%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2022\/07\/28\/%e6%9f%a0%e6%aa%ac%e5%be%ae%e8%b6%a3%e7%ac%94%e8%af%95%e9%a2%98-%e5%8f%8d%e8%bd%ac%e5%8d%95%e9%93%be%e8%a1%a8\/","title":{"rendered":"\u67e0\u6aac\u5fae\u8da3\u7b14\u8bd5\u9898-\u53cd\u8f6c\u5355\u94fe\u8868"},"content":{"rendered":"\n<p>\u770b\u5230\u53cd\u8f6c\u94fe\u8868\uff0c\u53ef\u80fd\u7b2c\u4e00\u65f6\u95f4\u7684\u60f3\u6cd5\u4fbf\u662f\u904d\u5386\u4e00\u904d\u8fd9\u4e2a\u5355\u94fe\u8868\uff0c\u7136\u540e\u628a\u94fe\u8868\u91cc\u7684\u5143\u7d20\u90fd\u53d6\u51fa\u6765\uff0c\u653e\u5230\u4e00\u4e2a\u6570\u7ec4\u91cc\uff0c\u7136\u540e\u9006\u7f6e\u8fd9\u4e2a\u6570\u7ec4\u3002\u8fd9\u4e2a\u60f3\u6cd5\u662f\u9519\u7684\uff01\uff01\uff01<\/p>\n\n\n\n<p>\u53cd\u8f6c\u4e00\u4e2a\u5355\u94fe\u8868\uff0c\u6211\u4eec\u9700\u8981\u7684\u662f\u6539\u53d8\u8fd9\u4e2a\u94fe\u8868\u5185\u8282\u70b9\u7684\u6307\u5411\u3002<\/p>\n\n\n\n<p>\u53cd\u8f6c\u94fe\u8868\u7b2c\u4e00\u6b65\uff1a<\/p>\n\n\n\n<p>\u5224\u65ad\u94fe\u8868\u662f\u5426\u4e3a\u7a7a\uff0c\u5982\u679c\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u76f4\u63a5\u8fd4\u56denull\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (this.head == null) { \/\/\u6ca1\u6709\u8282\u70b9\nreturn null;\n}<\/code><\/pre>\n\n\n\n<p>\u53cd\u8f6c\u94fe\u8868\u7b2c\u4e8c\u6b65\uff1a<\/p>\n\n\n\n<p>\u5224\u65ad\u94fe\u8868\u662f\u5426\u53ea\u6709\u4e00\u4e2a\u8282\u70b9\uff0c\u5982\u679c\u5934\u7ed3\u70b9\u7684\u4e0b\u4e00\u8282\u70b9\u7b49\u4e8e\u7a7a\uff0c\u5219\u8bf4\u660e\u8be5\u94fe\u8868\u53ea\u6709\u4e00\u4e2a\u8282\u70b9\uff0c\u5373\u8fd4\u56de\u5934\u7ed3\u70b9\u3002<\/p>\n\n\n\n<p><br>\u53cd\u8f6c\u94fe\u8868\u7b2c\u4e09\u6b65\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (this.head.next == null) { \/\/\u53ea\u6709\u4e00\u4e2a\u8282\u70b9\nreturn this.head;\n}<\/code><\/pre>\n\n\n\n<p>\/\/\u81f3\u5c11\u4e24\u4e2a\u8282\u70b9<br><br>\u7b2c\u4e09\u6b65\u8be6\u89e3\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Node cur=this.head.next;\nthis.head.next=null;\nwhile (cur!=null){\nNode curNext=cur.next;\ncur.next=head;\nthis.head=cur;\ncur=curNext;\n}\nreturn head;<\/code><\/pre>\n\n\n\n<p>\u94fe\u8868\u53cd\u8f6c\u540e\uff0c\u5b83\u539f\u672c\u7684\u5934\u7ed3\u70b9\u7684\u4e0b\u4e00\u8282\u70b9\u5c31\u4e3a\u7a7anull\u4e86\u3002\u4f46\u662f\u4e0d\u80fd\u5728\u4e00\u5f00\u59cb\u5c31\u5c06\u5934\u7ed3\u70b9\u7684\u4e0b\u4e00\u8282\u70b9\u7f6e\u4e3a\u7a7a\u3002\u56e0\u4e3a\u5c06\u5b83\u7f6e\u4e3a\u7a7a\u540e\uff0c\u4fbf\u5931\u53bb\u4e86\u4e0e\u94fe\u8868\u672c\u6765head.next\u7684\u8054\u7cfb\uff1b\u6240\u4ee5\uff0c\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2acur\u8bb0\u5f55\u5934\u7ed3\u70b9\u4e0b\u4e00\u8282\u70b9\u7684\u4f4d\u7f6e\uff1b\u4e5f\u5c31\u662f\u8bf4\u8ba9head\u4e0d\u52a8\uff0c\u5c06\u8bb0\u5f55\u5934\u7ed3\u70b9\u4e0b\u4e00\u8282\u70b9\u4f4d\u7f6e\u7684cur\u7528\u5934\u63d2\u6cd5\u7684\u65b9\u5f0f\u63d2\u5165\u5230head\u7684\u524d\u8fb9\uff0c\u5728cur\u5934\u63d2\u5230head\u524d\u518d\u5b9a\u4e49\u4e00\u4e2acurNext\u8bb0\u5f55cur\u7684\u4e0b\u4e00\u8282\u70b9\uff0c\u4f7fcur\u5230\u4e86head\u524d\uff0c\u4e5f\u4e0d\u4f1a\u5931\u53bb\u4e0e\u540e\u8fb9\u8282\u70b9\u7684\u8054\u7cfb\u3002\u5f53\u6240\u6709\u7684\u94fe\u8868\u90fd\u53cd\u8f6c\u540e\uff0ccur\u5c31\u4f1a\u4e3a\u7a7a\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>class Node{<br>public int val;<br>public Node next; \/\/\u7c7b\u578b\u662fNode null<\/p>\n\n\n\n<p>public Node(int val){<br>this.val=val;}<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>public class SingleLinkedList {<br>public Node head; \/\/\u53cd\u8f6c\u94fe\u8868<br>\/\/\u53cd\u8f6c\u94fe\u8868\u5e76\u4e0d\u80fd\u4f7f\u7528\u9006\u7f6e\u6570\u7ec4\uff0c\u9700\u8981\u6539\u53d8\u94fe\u8868\u5143\u7d20\u7684\u6307\u5411\uff08\u4f7f\u7528\u5934\u63d2\u6cd5\uff09<br>public Node reverseList() {<br>if (this.head == null) { \/\/\u6ca1\u6709\u8282\u70b9<br>return null;<br>}<br>if (this.head.next == null) { \/\/\u53ea\u6709\u4e00\u4e2a\u8282\u70b9<br>return this.head;<br>}<br>\/\/\u81f3\u5c11\u6709\u4e24\u4e2a\u8282\u70b9<br>Node cur=this.head.next;<br>this.head.next=null;<br>while (cur!=null){<br>Node curNext=cur.next;<br>cur.next=head;<br>this.head=cur;<br>cur=curNext;<br>}<br>return head;<br>}<br>}<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u770b\u5230\u53cd\u8f6c\u94fe\u8868\uff0c\u53ef\u80fd\u7b2c\u4e00\u65f6\u95f4\u7684\u60f3\u6cd5&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1381,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1377","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=1377"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1377\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=1377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=1377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=1377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}