<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Algorithm on kj’s blog</title><link>https://kfjie.me/zh-tw/tags/algorithm/</link><description>Recent content from kj’s blog</description><generator>Hugo</generator><language>zh-tw</language><managingEditor>None (Kfjie)</managingEditor><webMaster>None (Kfjie)</webMaster><copyright>本部落格所有文章除特別聲明外，均採用 BY-NC-SA 授權協議。轉載請註明出處！</copyright><lastBuildDate>Sun, 18 Oct 2026 20:00:00 +0800</lastBuildDate><atom:link href="https://kfjie.me/zh-tw/tags/algorithm/index.xml" rel="self" type="application/rss+xml"/><item><title>记录：链表反转</title><link>https://kfjie.me/zh-tw/post/reverse-linked-list/</link><pubDate>Sun, 18 Oct 2026 20:00:00 +0800</pubDate><author>None (Kfjie)</author><guid>https://kfjie.me/zh-tw/post/reverse-linked-list/</guid><description>
<![CDATA[<h1>记录：链表反转</h1><p>作者：Kfjie（None）</p>
        
          <p>r：单链表全反转</p>
<h2 id="先看这组链表">
<a class="header-anchor" href="#%e5%85%88%e7%9c%8b%e8%bf%99%e7%bb%84%e9%93%be%e8%a1%a8"></a>
先看这组链表
</h2><p>比如现在有这样一组链表：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">head
</span></span><span class="line"><span class="cl"> ↓
</span></span><span class="line"><span class="cl"> 1 → 2 → 3 → 4 → null
</span></span></code></pre></div><p>保持图中各个节点的位置不动，我们要把节点之间的指向反过来：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">null ← 1 ← 2 ← 3 ← 4
</span></span><span class="line"><span class="cl">                   ↑
</span></span><span class="line"><span class="cl">                  head
</span></span></code></pre></div><p>原来 <code>1</code> 是头节点，没有前一个节点；反转之后，<code>1</code> 就变成尾节点，它的 <code>next</code> 应该指向 <code>null</code>，新的头节点则是 <code>4</code>。</p>
        
        <hr><p>本文2026-10-18首發於<a href='https://kfjie.me/'>kj’s blog</a>，最後修改於2026-10-18</p>]]></description><category>Notes</category></item></channel></rss>