<?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/en/tags/algorithm/</link><description>Recent content from kj’s blog</description><generator>Hugo</generator><language>en</language><managingEditor>None (Kfjie)</managingEditor><webMaster>None (Kfjie)</webMaster><copyright>All articles on this blog are licensed under the BY-NC-SA license agreement unless otherwise stated. Please indicate the source when reprinting!</copyright><lastBuildDate>Sun, 18 Oct 2026 20:00:00 +0800</lastBuildDate><atom:link href="https://kfjie.me/en/tags/algorithm/index.xml" rel="self" type="application/rss+xml"/><item><title>Notes: Reversing a Linked List</title><link>https://kfjie.me/en/post/reverse-linked-list/</link><pubDate>Sun, 18 Oct 2026 20:00:00 +0800</pubDate><author>None (Kfjie)</author><guid>https://kfjie.me/en/post/reverse-linked-list/</guid><description>
<![CDATA[<h1>Notes: Reversing a Linked List</h1><p>Author: Kfjie(None)</p>
        
          <p>r: Reverse the entire singly linked list</p>
<h2 id="first-lets-look-at-this-set-of-linked-lists">
<a class="header-anchor" href="#first-lets-look-at-this-set-of-linked-lists"></a>
First, let&rsquo;s look at this set of linked lists
</h2><p>For example, suppose we have the following linked list:</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>While keeping the positions of the nodes in the diagram unchanged, we need to reverse the directions of the edges between the nodes:</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>It turns out that <code>1</code> It is a leaf node; there is no previous node. After reversal,<code>1</code> It then becomes a leaf node, and its <code>next</code> Should point to <code>null</code>, and the new root node is <code>4</code>。</p>
        
        <hr><p>Published on 2026-10-18 at <a href='https://kfjie.me/'>kj’s blog</a>, last modified on 2026-10-18</p>]]></description><category>Notes</category></item></channel></rss>