mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-24 10:46:29 +08:00
deploy
This commit is contained in:
parent
5584492f3d
commit
c5ce5ebd48
21 changed files with 1041 additions and 338 deletions
BIN
assets/course/hello-algo-0.1-课程简介.pdf
Normal file
BIN
assets/course/hello-algo-0.1-课程简介.pdf
Normal file
Binary file not shown.
|
@ -3468,18 +3468,27 @@
|
|||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#8-dart" class="md-nav__link">
|
||||
<a href="#8-typescript" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
8. Dart 环境
|
||||
8. TypeScript 环境
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#9-rust" class="md-nav__link">
|
||||
<a href="#9-dart" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
9. Rust 环境
|
||||
9. Dart 环境
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#10-rust" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
10. Rust 环境
|
||||
</span>
|
||||
</a>
|
||||
|
||||
|
@ -3779,18 +3788,27 @@
|
|||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#8-dart" class="md-nav__link">
|
||||
<a href="#8-typescript" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
8. Dart 环境
|
||||
8. TypeScript 环境
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#9-rust" class="md-nav__link">
|
||||
<a href="#9-dart" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
9. Rust 环境
|
||||
9. Dart 环境
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#10-rust" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
10. Rust 环境
|
||||
</span>
|
||||
</a>
|
||||
|
||||
|
@ -3884,16 +3902,21 @@
|
|||
</ol>
|
||||
<h3 id="7-javascript">7. JavaScript 环境<a class="headerlink" href="#7-javascript" title="Permanent link">¶</a></h3>
|
||||
<ol>
|
||||
<li>下载并安装 <a href="https://nodejs.org/en/">node.js</a> 。</li>
|
||||
<li>在 VS Code 的插件市场中搜索 <code>javascript</code> ,安装 JavaScript (ES6) code snippets 。</li>
|
||||
<li>下载并安装 <a href="https://nodejs.org/en/">Node.js</a> 。</li>
|
||||
<li>(可选)在 VS Code 的插件市场中搜索 <code>Prettier</code> ,安装代码格式化工具。</li>
|
||||
</ol>
|
||||
<h3 id="8-dart">8. Dart 环境<a class="headerlink" href="#8-dart" title="Permanent link">¶</a></h3>
|
||||
<h3 id="8-typescript">8. TypeScript 环境<a class="headerlink" href="#8-typescript" title="Permanent link">¶</a></h3>
|
||||
<ol>
|
||||
<li>同 JavaScript 环境安装步骤。</li>
|
||||
<li>安装 <a href="https://github.com/privatenumber/tsx?tab=readme-ov-file#global-installation">TypeScript Execute (tsx)</a> 。</li>
|
||||
<li>在 VS Code 的插件市场中搜索 <code>typescript</code> ,安装 <a href="https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors">Pretty TypeScript Errors</a> 。</li>
|
||||
</ol>
|
||||
<h3 id="9-dart">9. Dart 环境<a class="headerlink" href="#9-dart" title="Permanent link">¶</a></h3>
|
||||
<ol>
|
||||
<li>下载并安装 <a href="https://dart.dev/get-dart">Dart</a> 。</li>
|
||||
<li>在 VS Code 的插件市场中搜索 <code>dart</code> ,安装 <a href="https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code">Dart</a> 。</li>
|
||||
</ol>
|
||||
<h3 id="9-rust">9. Rust 环境<a class="headerlink" href="#9-rust" title="Permanent link">¶</a></h3>
|
||||
<h3 id="10-rust">10. Rust 环境<a class="headerlink" href="#10-rust" title="Permanent link">¶</a></h3>
|
||||
<ol>
|
||||
<li>下载并安装 <a href="https://www.rust-lang.org/tools/install">Rust</a> 。</li>
|
||||
<li>在 VS Code 的插件市场中搜索 <code>rust</code> ,安装 <a href="https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer">rust-analyzer</a> 。</li>
|
||||
|
|
|
@ -3638,17 +3638,18 @@
|
|||
<ul>
|
||||
<li>采用全彩印刷,能够原汁原味地发挥出本书“动画图解”的优势。</li>
|
||||
<li>考究纸张材质,既保证色彩高度还原,也保留纸质书特有的质感。</li>
|
||||
<li>纸质版比网页版的格式更加规范,例如图中的公式使用斜体。</li>
|
||||
<li>在不提升定价的前提下,附赠思维导图折页、书签。</li>
|
||||
<li>纸质书、网页版、PDF 版内容同步,随意切换阅读。</li>
|
||||
</ul>
|
||||
<div class="admonition tip">
|
||||
<p class="admonition-title">Tip</p>
|
||||
<p>由于纸质书和网页版的同步成本较大,因此可能会有一些细节上的不同,请您见谅!</p>
|
||||
<p>由于纸质书和网页版的同步难度较大,因此可能会有一些细节上的不同,请您见谅!</p>
|
||||
</div>
|
||||
<p>当然,纸质书也有一些值得大家入手前考虑的地方:</p>
|
||||
<ul>
|
||||
<li>使用 Python 语言,可能不匹配你的主语言(也许可以趁此机会练习 Python)。</li>
|
||||
<li>全彩印刷虽然大幅提升了阅读体验,但价格会比黑白印刷高一些。</li>
|
||||
<li>使用 Python 语言,可能不匹配你的主语言(可以把 Python 看作伪代码,重在理解思路)。</li>
|
||||
<li>全彩印刷虽然大幅提升了图解和代码的阅读体验,但价格会比黑白印刷高一些。</li>
|
||||
</ul>
|
||||
<div class="admonition tip">
|
||||
<p class="admonition-title">Tip</p>
|
||||
|
|
|
@ -4870,7 +4870,87 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">array_binary_tree.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">ArrayBinaryTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{}</span>
|
||||
<div class="highlight"><span class="filename">array_binary_tree.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="c1">### 数组表示下的二叉树类 ###</span>
|
||||
<a id="__codelineno-26-2" name="__codelineno-26-2" href="#__codelineno-26-2"></a><span class="k">class</span><span class="w"> </span><span class="nc">ArrayBinaryTree</span>
|
||||
<a id="__codelineno-26-3" name="__codelineno-26-3" href="#__codelineno-26-3"></a><span class="w"> </span><span class="c1">### 构造方法 ###</span>
|
||||
<a id="__codelineno-26-4" name="__codelineno-26-4" href="#__codelineno-26-4"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">initialize</span><span class="p">(</span><span class="n">arr</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-5" name="__codelineno-26-5" href="#__codelineno-26-5"></a><span class="w"> </span><span class="vi">@tree</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">arr</span><span class="o">.</span><span class="n">to_a</span>
|
||||
<a id="__codelineno-26-6" name="__codelineno-26-6" href="#__codelineno-26-6"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-7" name="__codelineno-26-7" href="#__codelineno-26-7"></a>
|
||||
<a id="__codelineno-26-8" name="__codelineno-26-8" href="#__codelineno-26-8"></a><span class="w"> </span><span class="c1">### 列表容量 ###</span>
|
||||
<a id="__codelineno-26-9" name="__codelineno-26-9" href="#__codelineno-26-9"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">size</span>
|
||||
<a id="__codelineno-26-10" name="__codelineno-26-10" href="#__codelineno-26-10"></a><span class="w"> </span><span class="vi">@tree</span><span class="o">.</span><span class="n">length</span>
|
||||
<a id="__codelineno-26-11" name="__codelineno-26-11" href="#__codelineno-26-11"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-12" name="__codelineno-26-12" href="#__codelineno-26-12"></a>
|
||||
<a id="__codelineno-26-13" name="__codelineno-26-13" href="#__codelineno-26-13"></a><span class="w"> </span><span class="c1">### 获取索引为 i 节点的值 ###</span>
|
||||
<a id="__codelineno-26-14" name="__codelineno-26-14" href="#__codelineno-26-14"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-15" name="__codelineno-26-15" href="#__codelineno-26-15"></a><span class="w"> </span><span class="c1"># 若索引越界,则返回 nil ,代表空位</span>
|
||||
<a id="__codelineno-26-16" name="__codelineno-26-16" href="#__codelineno-26-16"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="n">size</span>
|
||||
<a id="__codelineno-26-17" name="__codelineno-26-17" href="#__codelineno-26-17"></a>
|
||||
<a id="__codelineno-26-18" name="__codelineno-26-18" href="#__codelineno-26-18"></a><span class="w"> </span><span class="vi">@tree</span><span class="o">[</span><span class="n">i</span><span class="o">]</span>
|
||||
<a id="__codelineno-26-19" name="__codelineno-26-19" href="#__codelineno-26-19"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-20" name="__codelineno-26-20" href="#__codelineno-26-20"></a>
|
||||
<a id="__codelineno-26-21" name="__codelineno-26-21" href="#__codelineno-26-21"></a><span class="w"> </span><span class="c1">### 获取索引为 i 节点的左子节点的索引 ###</span>
|
||||
<a id="__codelineno-26-22" name="__codelineno-26-22" href="#__codelineno-26-22"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">left</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-23" name="__codelineno-26-23" href="#__codelineno-26-23"></a><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span>
|
||||
<a id="__codelineno-26-24" name="__codelineno-26-24" href="#__codelineno-26-24"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-25" name="__codelineno-26-25" href="#__codelineno-26-25"></a>
|
||||
<a id="__codelineno-26-26" name="__codelineno-26-26" href="#__codelineno-26-26"></a><span class="w"> </span><span class="c1">### 获取索引为 i 节点的右子节点的索引 ###</span>
|
||||
<a id="__codelineno-26-27" name="__codelineno-26-27" href="#__codelineno-26-27"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">right</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-28" name="__codelineno-26-28" href="#__codelineno-26-28"></a><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">2</span>
|
||||
<a id="__codelineno-26-29" name="__codelineno-26-29" href="#__codelineno-26-29"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-30" name="__codelineno-26-30" href="#__codelineno-26-30"></a>
|
||||
<a id="__codelineno-26-31" name="__codelineno-26-31" href="#__codelineno-26-31"></a><span class="w"> </span><span class="c1">### 获取索引为 i 节点的父节点的索引 ###</span>
|
||||
<a id="__codelineno-26-32" name="__codelineno-26-32" href="#__codelineno-26-32"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">parent</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-33" name="__codelineno-26-33" href="#__codelineno-26-33"></a><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="mi">2</span>
|
||||
<a id="__codelineno-26-34" name="__codelineno-26-34" href="#__codelineno-26-34"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-35" name="__codelineno-26-35" href="#__codelineno-26-35"></a>
|
||||
<a id="__codelineno-26-36" name="__codelineno-26-36" href="#__codelineno-26-36"></a><span class="w"> </span><span class="c1">### 层序遍历 ###</span>
|
||||
<a id="__codelineno-26-37" name="__codelineno-26-37" href="#__codelineno-26-37"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">level_order</span>
|
||||
<a id="__codelineno-26-38" name="__codelineno-26-38" href="#__codelineno-26-38"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[]</span>
|
||||
<a id="__codelineno-26-39" name="__codelineno-26-39" href="#__codelineno-26-39"></a>
|
||||
<a id="__codelineno-26-40" name="__codelineno-26-40" href="#__codelineno-26-40"></a><span class="w"> </span><span class="c1"># 直接遍历数组</span>
|
||||
<a id="__codelineno-26-41" name="__codelineno-26-41" href="#__codelineno-26-41"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="mi">0</span><span class="o">...</span><span class="n">size</span>
|
||||
<a id="__codelineno-26-42" name="__codelineno-26-42" href="#__codelineno-26-42"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="k">unless</span><span class="w"> </span><span class="n">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-43" name="__codelineno-26-43" href="#__codelineno-26-43"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-44" name="__codelineno-26-44" href="#__codelineno-26-44"></a>
|
||||
<a id="__codelineno-26-45" name="__codelineno-26-45" href="#__codelineno-26-45"></a><span class="w"> </span><span class="vi">@res</span>
|
||||
<a id="__codelineno-26-46" name="__codelineno-26-46" href="#__codelineno-26-46"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-47" name="__codelineno-26-47" href="#__codelineno-26-47"></a>
|
||||
<a id="__codelineno-26-48" name="__codelineno-26-48" href="#__codelineno-26-48"></a><span class="w"> </span><span class="c1">### 深度优先遍历 ###</span>
|
||||
<a id="__codelineno-26-49" name="__codelineno-26-49" href="#__codelineno-26-49"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">dfs</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">order</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-50" name="__codelineno-26-50" href="#__codelineno-26-50"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-51" name="__codelineno-26-51" href="#__codelineno-26-51"></a><span class="w"> </span><span class="c1"># 前序遍历</span>
|
||||
<a id="__codelineno-26-52" name="__codelineno-26-52" href="#__codelineno-26-52"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">order</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="ss">:pre</span>
|
||||
<a id="__codelineno-26-53" name="__codelineno-26-53" href="#__codelineno-26-53"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">left</span><span class="p">(</span><span class="n">i</span><span class="p">),</span><span class="w"> </span><span class="n">order</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-54" name="__codelineno-26-54" href="#__codelineno-26-54"></a><span class="w"> </span><span class="c1"># 中序遍历</span>
|
||||
<a id="__codelineno-26-55" name="__codelineno-26-55" href="#__codelineno-26-55"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">order</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="ss">:in</span>
|
||||
<a id="__codelineno-26-56" name="__codelineno-26-56" href="#__codelineno-26-56"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">right</span><span class="p">(</span><span class="n">i</span><span class="p">),</span><span class="w"> </span><span class="n">order</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-57" name="__codelineno-26-57" href="#__codelineno-26-57"></a><span class="w"> </span><span class="c1"># 后序遍历</span>
|
||||
<a id="__codelineno-26-58" name="__codelineno-26-58" href="#__codelineno-26-58"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">order</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="ss">:post</span>
|
||||
<a id="__codelineno-26-59" name="__codelineno-26-59" href="#__codelineno-26-59"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-60" name="__codelineno-26-60" href="#__codelineno-26-60"></a>
|
||||
<a id="__codelineno-26-61" name="__codelineno-26-61" href="#__codelineno-26-61"></a><span class="w"> </span><span class="c1">### 前序遍历 ###</span>
|
||||
<a id="__codelineno-26-62" name="__codelineno-26-62" href="#__codelineno-26-62"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">pre_order</span>
|
||||
<a id="__codelineno-26-63" name="__codelineno-26-63" href="#__codelineno-26-63"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[]</span>
|
||||
<a id="__codelineno-26-64" name="__codelineno-26-64" href="#__codelineno-26-64"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="ss">:pre</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-65" name="__codelineno-26-65" href="#__codelineno-26-65"></a><span class="w"> </span><span class="vi">@res</span>
|
||||
<a id="__codelineno-26-66" name="__codelineno-26-66" href="#__codelineno-26-66"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-67" name="__codelineno-26-67" href="#__codelineno-26-67"></a>
|
||||
<a id="__codelineno-26-68" name="__codelineno-26-68" href="#__codelineno-26-68"></a><span class="w"> </span><span class="c1">### 中序遍历 ###</span>
|
||||
<a id="__codelineno-26-69" name="__codelineno-26-69" href="#__codelineno-26-69"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">in_order</span>
|
||||
<a id="__codelineno-26-70" name="__codelineno-26-70" href="#__codelineno-26-70"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[]</span>
|
||||
<a id="__codelineno-26-71" name="__codelineno-26-71" href="#__codelineno-26-71"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="ss">:in</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-72" name="__codelineno-26-72" href="#__codelineno-26-72"></a><span class="w"> </span><span class="vi">@res</span>
|
||||
<a id="__codelineno-26-73" name="__codelineno-26-73" href="#__codelineno-26-73"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-74" name="__codelineno-26-74" href="#__codelineno-26-74"></a>
|
||||
<a id="__codelineno-26-75" name="__codelineno-26-75" href="#__codelineno-26-75"></a><span class="w"> </span><span class="c1">### 后序遍历 ###</span>
|
||||
<a id="__codelineno-26-76" name="__codelineno-26-76" href="#__codelineno-26-76"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">post_order</span>
|
||||
<a id="__codelineno-26-77" name="__codelineno-26-77" href="#__codelineno-26-77"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[]</span>
|
||||
<a id="__codelineno-26-78" name="__codelineno-26-78" href="#__codelineno-26-78"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="ss">:post</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-79" name="__codelineno-26-79" href="#__codelineno-26-79"></a><span class="w"> </span><span class="vi">@res</span>
|
||||
<a id="__codelineno-26-80" name="__codelineno-26-80" href="#__codelineno-26-80"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-81" name="__codelineno-26-81" href="#__codelineno-26-81"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
|
@ -4308,9 +4308,19 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">height</span><span class="p">}</span>
|
||||
<a id="__codelineno-26-2" name="__codelineno-26-2" href="#__codelineno-26-2"></a>
|
||||
<a id="__codelineno-26-3" name="__codelineno-26-3" href="#__codelineno-26-3"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">update_height</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="c1">### 获取节点高度 ###</span>
|
||||
<a id="__codelineno-26-2" name="__codelineno-26-2" href="#__codelineno-26-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">height</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-3" name="__codelineno-26-3" href="#__codelineno-26-3"></a><span class="w"> </span><span class="c1"># 空节点高度为 -1 ,叶节点高度为 0</span>
|
||||
<a id="__codelineno-26-4" name="__codelineno-26-4" href="#__codelineno-26-4"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">height</span><span class="w"> </span><span class="k">unless</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-5" name="__codelineno-26-5" href="#__codelineno-26-5"></a>
|
||||
<a id="__codelineno-26-6" name="__codelineno-26-6" href="#__codelineno-26-6"></a><span class="w"> </span><span class="o">-</span><span class="mi">1</span>
|
||||
<a id="__codelineno-26-7" name="__codelineno-26-7" href="#__codelineno-26-7"></a><span class="k">end</span>
|
||||
<a id="__codelineno-26-8" name="__codelineno-26-8" href="#__codelineno-26-8"></a>
|
||||
<a id="__codelineno-26-9" name="__codelineno-26-9" href="#__codelineno-26-9"></a><span class="c1">### 更新节点高度 ###</span>
|
||||
<a id="__codelineno-26-10" name="__codelineno-26-10" href="#__codelineno-26-10"></a><span class="k">def</span><span class="w"> </span><span class="nf">update_height</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-11" name="__codelineno-26-11" href="#__codelineno-26-11"></a><span class="w"> </span><span class="c1"># 节点高度等于最高子树高度 + 1</span>
|
||||
<a id="__codelineno-26-12" name="__codelineno-26-12" href="#__codelineno-26-12"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">height</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[</span><span class="n">height</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="p">),</span><span class="w"> </span><span class="n">height</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">)</span><span class="o">].</span><span class="n">max</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span>
|
||||
<a id="__codelineno-26-13" name="__codelineno-26-13" href="#__codelineno-26-13"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -4465,7 +4475,14 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-40-1" name="__codelineno-40-1" href="#__codelineno-40-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">balance_factor</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-40-1" name="__codelineno-40-1" href="#__codelineno-40-1"></a><span class="c1">### 获取平衡因子 ###</span>
|
||||
<a id="__codelineno-40-2" name="__codelineno-40-2" href="#__codelineno-40-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">balance_factor</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-40-3" name="__codelineno-40-3" href="#__codelineno-40-3"></a><span class="w"> </span><span class="c1"># 空节点平衡因子为 0</span>
|
||||
<a id="__codelineno-40-4" name="__codelineno-40-4" href="#__codelineno-40-4"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-40-5" name="__codelineno-40-5" href="#__codelineno-40-5"></a>
|
||||
<a id="__codelineno-40-6" name="__codelineno-40-6" href="#__codelineno-40-6"></a><span class="w"> </span><span class="c1"># 节点平衡因子 = 左子树高度 - 右子树高度</span>
|
||||
<a id="__codelineno-40-7" name="__codelineno-40-7" href="#__codelineno-40-7"></a><span class="w"> </span><span class="n">height</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="p">)</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">height</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">)</span>
|
||||
<a id="__codelineno-40-8" name="__codelineno-40-8" href="#__codelineno-40-8"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -4712,7 +4729,19 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-54-1" name="__codelineno-54-1" href="#__codelineno-54-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">right_rotate</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-54-1" name="__codelineno-54-1" href="#__codelineno-54-1"></a><span class="c1">### 右旋操作 ###</span>
|
||||
<a id="__codelineno-54-2" name="__codelineno-54-2" href="#__codelineno-54-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">right_rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-54-3" name="__codelineno-54-3" href="#__codelineno-54-3"></a><span class="w"> </span><span class="n">child</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-54-4" name="__codelineno-54-4" href="#__codelineno-54-4"></a><span class="w"> </span><span class="n">grand_child</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">child</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-54-5" name="__codelineno-54-5" href="#__codelineno-54-5"></a><span class="w"> </span><span class="c1"># 以 child 为原点,将 node 向右旋转</span>
|
||||
<a id="__codelineno-54-6" name="__codelineno-54-6" href="#__codelineno-54-6"></a><span class="w"> </span><span class="n">child</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span>
|
||||
<a id="__codelineno-54-7" name="__codelineno-54-7" href="#__codelineno-54-7"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">grand_child</span>
|
||||
<a id="__codelineno-54-8" name="__codelineno-54-8" href="#__codelineno-54-8"></a><span class="w"> </span><span class="c1"># 更新节点高度</span>
|
||||
<a id="__codelineno-54-9" name="__codelineno-54-9" href="#__codelineno-54-9"></a><span class="w"> </span><span class="n">update_height</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-54-10" name="__codelineno-54-10" href="#__codelineno-54-10"></a><span class="w"> </span><span class="n">update_height</span><span class="p">(</span><span class="n">child</span><span class="p">)</span>
|
||||
<a id="__codelineno-54-11" name="__codelineno-54-11" href="#__codelineno-54-11"></a><span class="w"> </span><span class="c1"># 返回旋转后子树的根节点</span>
|
||||
<a id="__codelineno-54-12" name="__codelineno-54-12" href="#__codelineno-54-12"></a><span class="w"> </span><span class="n">child</span>
|
||||
<a id="__codelineno-54-13" name="__codelineno-54-13" href="#__codelineno-54-13"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -4943,7 +4972,19 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-68-1" name="__codelineno-68-1" href="#__codelineno-68-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">left_rotate</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-68-1" name="__codelineno-68-1" href="#__codelineno-68-1"></a><span class="c1">### 左旋操作 ###</span>
|
||||
<a id="__codelineno-68-2" name="__codelineno-68-2" href="#__codelineno-68-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">left_rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-68-3" name="__codelineno-68-3" href="#__codelineno-68-3"></a><span class="w"> </span><span class="n">child</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-68-4" name="__codelineno-68-4" href="#__codelineno-68-4"></a><span class="w"> </span><span class="n">grand_child</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">child</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-68-5" name="__codelineno-68-5" href="#__codelineno-68-5"></a><span class="w"> </span><span class="c1"># 以 child 为原点,将 node 向左旋转</span>
|
||||
<a id="__codelineno-68-6" name="__codelineno-68-6" href="#__codelineno-68-6"></a><span class="w"> </span><span class="n">child</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span>
|
||||
<a id="__codelineno-68-7" name="__codelineno-68-7" href="#__codelineno-68-7"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">grand_child</span>
|
||||
<a id="__codelineno-68-8" name="__codelineno-68-8" href="#__codelineno-68-8"></a><span class="w"> </span><span class="c1"># 更新节点高度</span>
|
||||
<a id="__codelineno-68-9" name="__codelineno-68-9" href="#__codelineno-68-9"></a><span class="w"> </span><span class="n">update_height</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-68-10" name="__codelineno-68-10" href="#__codelineno-68-10"></a><span class="w"> </span><span class="n">update_height</span><span class="p">(</span><span class="n">child</span><span class="p">)</span>
|
||||
<a id="__codelineno-68-11" name="__codelineno-68-11" href="#__codelineno-68-11"></a><span class="w"> </span><span class="c1"># 返回旋转后子树的根节点</span>
|
||||
<a id="__codelineno-68-12" name="__codelineno-68-12" href="#__codelineno-68-12"></a><span class="w"> </span><span class="n">child</span>
|
||||
<a id="__codelineno-68-13" name="__codelineno-68-13" href="#__codelineno-68-13"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -5404,7 +5445,34 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-82-1" name="__codelineno-82-1" href="#__codelineno-82-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">rotate</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-82-1" name="__codelineno-82-1" href="#__codelineno-82-1"></a><span class="c1">### 执行旋转操作,使该子树重新恢复平衡 ###</span>
|
||||
<a id="__codelineno-82-2" name="__codelineno-82-2" href="#__codelineno-82-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-3" name="__codelineno-82-3" href="#__codelineno-82-3"></a><span class="w"> </span><span class="c1"># 获取节点 node 的平衡因子</span>
|
||||
<a id="__codelineno-82-4" name="__codelineno-82-4" href="#__codelineno-82-4"></a><span class="w"> </span><span class="n">balance_factor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">balance_factor</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-5" name="__codelineno-82-5" href="#__codelineno-82-5"></a><span class="w"> </span><span class="c1"># 左遍树</span>
|
||||
<a id="__codelineno-82-6" name="__codelineno-82-6" href="#__codelineno-82-6"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">balance_factor</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="mi">1</span>
|
||||
<a id="__codelineno-82-7" name="__codelineno-82-7" href="#__codelineno-82-7"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">balance_factor</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="p">)</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="mi">0</span>
|
||||
<a id="__codelineno-82-8" name="__codelineno-82-8" href="#__codelineno-82-8"></a><span class="w"> </span><span class="c1"># 右旋</span>
|
||||
<a id="__codelineno-82-9" name="__codelineno-82-9" href="#__codelineno-82-9"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">right_rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-10" name="__codelineno-82-10" href="#__codelineno-82-10"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-82-11" name="__codelineno-82-11" href="#__codelineno-82-11"></a><span class="w"> </span><span class="c1"># 先左旋后右旋</span>
|
||||
<a id="__codelineno-82-12" name="__codelineno-82-12" href="#__codelineno-82-12"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">left_rotate</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-13" name="__codelineno-82-13" href="#__codelineno-82-13"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">right_rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-14" name="__codelineno-82-14" href="#__codelineno-82-14"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-82-15" name="__codelineno-82-15" href="#__codelineno-82-15"></a><span class="w"> </span><span class="c1"># 右遍树</span>
|
||||
<a id="__codelineno-82-16" name="__codelineno-82-16" href="#__codelineno-82-16"></a><span class="w"> </span><span class="k">elsif</span><span class="w"> </span><span class="n">balance_factor</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span>
|
||||
<a id="__codelineno-82-17" name="__codelineno-82-17" href="#__codelineno-82-17"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">balance_factor</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">)</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="mi">0</span>
|
||||
<a id="__codelineno-82-18" name="__codelineno-82-18" href="#__codelineno-82-18"></a><span class="w"> </span><span class="c1"># 左旋</span>
|
||||
<a id="__codelineno-82-19" name="__codelineno-82-19" href="#__codelineno-82-19"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">left_rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-20" name="__codelineno-82-20" href="#__codelineno-82-20"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-82-21" name="__codelineno-82-21" href="#__codelineno-82-21"></a><span class="w"> </span><span class="c1"># 先右旋后左旋</span>
|
||||
<a id="__codelineno-82-22" name="__codelineno-82-22" href="#__codelineno-82-22"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">right_rotate</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-23" name="__codelineno-82-23" href="#__codelineno-82-23"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">left_rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-24" name="__codelineno-82-24" href="#__codelineno-82-24"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-82-25" name="__codelineno-82-25" href="#__codelineno-82-25"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-82-26" name="__codelineno-82-26" href="#__codelineno-82-26"></a><span class="w"> </span><span class="c1"># 平衡树,无须旋转,直接返回</span>
|
||||
<a id="__codelineno-82-27" name="__codelineno-82-27" href="#__codelineno-82-27"></a><span class="w"> </span><span class="n">node</span>
|
||||
<a id="__codelineno-82-28" name="__codelineno-82-28" href="#__codelineno-82-28"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -5768,9 +5836,28 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-96-1" name="__codelineno-96-1" href="#__codelineno-96-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">insert</span><span class="p">}</span>
|
||||
<a id="__codelineno-96-2" name="__codelineno-96-2" href="#__codelineno-96-2"></a>
|
||||
<a id="__codelineno-96-3" name="__codelineno-96-3" href="#__codelineno-96-3"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">insert_helper</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-96-1" name="__codelineno-96-1" href="#__codelineno-96-1"></a><span class="c1">### 插入节点 ###</span>
|
||||
<a id="__codelineno-96-2" name="__codelineno-96-2" href="#__codelineno-96-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">insert</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-3" name="__codelineno-96-3" href="#__codelineno-96-3"></a><span class="w"> </span><span class="vi">@root</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">insert_helper</span><span class="p">(</span><span class="vi">@root</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-4" name="__codelineno-96-4" href="#__codelineno-96-4"></a><span class="k">end</span>
|
||||
<a id="__codelineno-96-5" name="__codelineno-96-5" href="#__codelineno-96-5"></a>
|
||||
<a id="__codelineno-96-6" name="__codelineno-96-6" href="#__codelineno-96-6"></a><span class="c1">### 递归插入节点(辅助方法)###</span>
|
||||
<a id="__codelineno-96-7" name="__codelineno-96-7" href="#__codelineno-96-7"></a><span class="k">def</span><span class="w"> </span><span class="nf">insert_helper</span><span class="p">(</span><span class="n">node</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-8" name="__codelineno-96-8" href="#__codelineno-96-8"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="no">TreeNode</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">val</span><span class="p">)</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-96-9" name="__codelineno-96-9" href="#__codelineno-96-9"></a><span class="w"> </span><span class="c1"># 1. 查找插入位置并插入节点</span>
|
||||
<a id="__codelineno-96-10" name="__codelineno-96-10" href="#__codelineno-96-10"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">val</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-96-11" name="__codelineno-96-11" href="#__codelineno-96-11"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">insert_helper</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-12" name="__codelineno-96-12" href="#__codelineno-96-12"></a><span class="w"> </span><span class="k">elsif</span><span class="w"> </span><span class="n">val</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-96-13" name="__codelineno-96-13" href="#__codelineno-96-13"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">insert_helper</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-14" name="__codelineno-96-14" href="#__codelineno-96-14"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-96-15" name="__codelineno-96-15" href="#__codelineno-96-15"></a><span class="w"> </span><span class="c1"># 重复节点不插入,直接返回</span>
|
||||
<a id="__codelineno-96-16" name="__codelineno-96-16" href="#__codelineno-96-16"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">node</span>
|
||||
<a id="__codelineno-96-17" name="__codelineno-96-17" href="#__codelineno-96-17"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-96-18" name="__codelineno-96-18" href="#__codelineno-96-18"></a><span class="w"> </span><span class="c1"># 更新节点高度</span>
|
||||
<a id="__codelineno-96-19" name="__codelineno-96-19" href="#__codelineno-96-19"></a><span class="w"> </span><span class="n">update_height</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-20" name="__codelineno-96-20" href="#__codelineno-96-20"></a><span class="w"> </span><span class="c1"># 2. 执行旋转操作,使该子树重新恢复平衡</span>
|
||||
<a id="__codelineno-96-21" name="__codelineno-96-21" href="#__codelineno-96-21"></a><span class="w"> </span><span class="n">rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-22" name="__codelineno-96-22" href="#__codelineno-96-22"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -6343,9 +6430,41 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-110-1" name="__codelineno-110-1" href="#__codelineno-110-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">remove</span><span class="p">}</span>
|
||||
<a id="__codelineno-110-2" name="__codelineno-110-2" href="#__codelineno-110-2"></a>
|
||||
<a id="__codelineno-110-3" name="__codelineno-110-3" href="#__codelineno-110-3"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">remove_helper</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-110-1" name="__codelineno-110-1" href="#__codelineno-110-1"></a><span class="c1">### 删除节点 ###</span>
|
||||
<a id="__codelineno-110-2" name="__codelineno-110-2" href="#__codelineno-110-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">remove</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-3" name="__codelineno-110-3" href="#__codelineno-110-3"></a><span class="w"> </span><span class="vi">@root</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">remove_helper</span><span class="p">(</span><span class="vi">@root</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-4" name="__codelineno-110-4" href="#__codelineno-110-4"></a><span class="k">end</span>
|
||||
<a id="__codelineno-110-5" name="__codelineno-110-5" href="#__codelineno-110-5"></a>
|
||||
<a id="__codelineno-110-6" name="__codelineno-110-6" href="#__codelineno-110-6"></a><span class="c1">### 递归删除节点(辅助方法)###</span>
|
||||
<a id="__codelineno-110-7" name="__codelineno-110-7" href="#__codelineno-110-7"></a><span class="k">def</span><span class="w"> </span><span class="nf">remove_helper</span><span class="p">(</span><span class="n">node</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-8" name="__codelineno-110-8" href="#__codelineno-110-8"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-110-9" name="__codelineno-110-9" href="#__codelineno-110-9"></a><span class="w"> </span><span class="c1"># 1. 查找节点并删除</span>
|
||||
<a id="__codelineno-110-10" name="__codelineno-110-10" href="#__codelineno-110-10"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">val</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-110-11" name="__codelineno-110-11" href="#__codelineno-110-11"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">remove_helper</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-12" name="__codelineno-110-12" href="#__codelineno-110-12"></a><span class="w"> </span><span class="k">elsif</span><span class="w"> </span><span class="n">val</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-110-13" name="__codelineno-110-13" href="#__codelineno-110-13"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">remove_helper</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-14" name="__codelineno-110-14" href="#__codelineno-110-14"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-110-15" name="__codelineno-110-15" href="#__codelineno-110-15"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">nil?</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-110-16" name="__codelineno-110-16" href="#__codelineno-110-16"></a><span class="w"> </span><span class="n">child</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-110-17" name="__codelineno-110-17" href="#__codelineno-110-17"></a><span class="w"> </span><span class="c1"># 子节点数量 = 0 ,直接删除 node 并返回</span>
|
||||
<a id="__codelineno-110-18" name="__codelineno-110-18" href="#__codelineno-110-18"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">child</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-110-19" name="__codelineno-110-19" href="#__codelineno-110-19"></a><span class="w"> </span><span class="c1"># 子节点数量 = 1 ,直接删除 node</span>
|
||||
<a id="__codelineno-110-20" name="__codelineno-110-20" href="#__codelineno-110-20"></a><span class="w"> </span><span class="n">node</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">child</span>
|
||||
<a id="__codelineno-110-21" name="__codelineno-110-21" href="#__codelineno-110-21"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-110-22" name="__codelineno-110-22" href="#__codelineno-110-22"></a><span class="w"> </span><span class="c1"># 子节点数量 = 2 ,则将中序遍历的下个节点删除,并用该节点替换当前节点</span>
|
||||
<a id="__codelineno-110-23" name="__codelineno-110-23" href="#__codelineno-110-23"></a><span class="w"> </span><span class="n">temp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-110-24" name="__codelineno-110-24" href="#__codelineno-110-24"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="o">!</span><span class="n">temp</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-110-25" name="__codelineno-110-25" href="#__codelineno-110-25"></a><span class="w"> </span><span class="n">temp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">temp</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-110-26" name="__codelineno-110-26" href="#__codelineno-110-26"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-110-27" name="__codelineno-110-27" href="#__codelineno-110-27"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">remove_helper</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">,</span><span class="w"> </span><span class="n">temp</span><span class="o">.</span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-28" name="__codelineno-110-28" href="#__codelineno-110-28"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">temp</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-110-29" name="__codelineno-110-29" href="#__codelineno-110-29"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-110-30" name="__codelineno-110-30" href="#__codelineno-110-30"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-110-31" name="__codelineno-110-31" href="#__codelineno-110-31"></a><span class="w"> </span><span class="c1"># 更新节点高度</span>
|
||||
<a id="__codelineno-110-32" name="__codelineno-110-32" href="#__codelineno-110-32"></a><span class="w"> </span><span class="n">update_height</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-33" name="__codelineno-110-33" href="#__codelineno-110-33"></a><span class="w"> </span><span class="c1"># 2. 执行旋转操作,使该子树重新恢复平衡</span>
|
||||
<a id="__codelineno-110-34" name="__codelineno-110-34" href="#__codelineno-110-34"></a><span class="w"> </span><span class="n">rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-35" name="__codelineno-110-35" href="#__codelineno-110-35"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
|
@ -4053,7 +4053,26 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">binary_search_tree.rb</span><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">BinarySearchTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">search</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">binary_search_tree.rb</span><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a><span class="c1">### 查找节点 ###</span>
|
||||
<a id="__codelineno-12-2" name="__codelineno-12-2" href="#__codelineno-12-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">search</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
|
||||
<a id="__codelineno-12-3" name="__codelineno-12-3" href="#__codelineno-12-3"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="vi">@root</span>
|
||||
<a id="__codelineno-12-4" name="__codelineno-12-4" href="#__codelineno-12-4"></a>
|
||||
<a id="__codelineno-12-5" name="__codelineno-12-5" href="#__codelineno-12-5"></a><span class="w"> </span><span class="c1"># 循环查找,越过叶节点后跳出</span>
|
||||
<a id="__codelineno-12-6" name="__codelineno-12-6" href="#__codelineno-12-6"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="o">!</span><span class="n">cur</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-12-7" name="__codelineno-12-7" href="#__codelineno-12-7"></a><span class="w"> </span><span class="c1"># 目标节点在 cur 的右子树中</span>
|
||||
<a id="__codelineno-12-8" name="__codelineno-12-8" href="#__codelineno-12-8"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-12-9" name="__codelineno-12-9" href="#__codelineno-12-9"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-12-10" name="__codelineno-12-10" href="#__codelineno-12-10"></a><span class="w"> </span><span class="c1"># 目标节点在 cur 的左子树中</span>
|
||||
<a id="__codelineno-12-11" name="__codelineno-12-11" href="#__codelineno-12-11"></a><span class="w"> </span><span class="k">elsif</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-12-12" name="__codelineno-12-12" href="#__codelineno-12-12"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-12-13" name="__codelineno-12-13" href="#__codelineno-12-13"></a><span class="w"> </span><span class="c1"># 找到目标节点,跳出循环</span>
|
||||
<a id="__codelineno-12-14" name="__codelineno-12-14" href="#__codelineno-12-14"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-12-15" name="__codelineno-12-15" href="#__codelineno-12-15"></a><span class="w"> </span><span class="k">break</span>
|
||||
<a id="__codelineno-12-16" name="__codelineno-12-16" href="#__codelineno-12-16"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-12-17" name="__codelineno-12-17" href="#__codelineno-12-17"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-12-18" name="__codelineno-12-18" href="#__codelineno-12-18"></a>
|
||||
<a id="__codelineno-12-19" name="__codelineno-12-19" href="#__codelineno-12-19"></a><span class="w"> </span><span class="n">cur</span>
|
||||
<a id="__codelineno-12-20" name="__codelineno-12-20" href="#__codelineno-12-20"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -4484,7 +4503,38 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">binary_search_tree.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">BinarySearchTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">insert</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">binary_search_tree.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="c1">### 插入节点 ###</span>
|
||||
<a id="__codelineno-26-2" name="__codelineno-26-2" href="#__codelineno-26-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">insert</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-3" name="__codelineno-26-3" href="#__codelineno-26-3"></a><span class="w"> </span><span class="c1"># 若树为空,则初始化根节点</span>
|
||||
<a id="__codelineno-26-4" name="__codelineno-26-4" href="#__codelineno-26-4"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="vi">@root</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-5" name="__codelineno-26-5" href="#__codelineno-26-5"></a><span class="w"> </span><span class="vi">@root</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="no">TreeNode</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-6" name="__codelineno-26-6" href="#__codelineno-26-6"></a><span class="w"> </span><span class="k">return</span>
|
||||
<a id="__codelineno-26-7" name="__codelineno-26-7" href="#__codelineno-26-7"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-8" name="__codelineno-26-8" href="#__codelineno-26-8"></a>
|
||||
<a id="__codelineno-26-9" name="__codelineno-26-9" href="#__codelineno-26-9"></a><span class="w"> </span><span class="c1"># 循环查找,越过叶节点后跳出</span>
|
||||
<a id="__codelineno-26-10" name="__codelineno-26-10" href="#__codelineno-26-10"></a><span class="w"> </span><span class="n">cur</span><span class="p">,</span><span class="w"> </span><span class="n">pre</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="vi">@root</span><span class="p">,</span><span class="w"> </span><span class="kp">nil</span>
|
||||
<a id="__codelineno-26-11" name="__codelineno-26-11" href="#__codelineno-26-11"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="o">!</span><span class="n">cur</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-12" name="__codelineno-26-12" href="#__codelineno-26-12"></a><span class="w"> </span><span class="c1"># 找到重复节点,直接返回</span>
|
||||
<a id="__codelineno-26-13" name="__codelineno-26-13" href="#__codelineno-26-13"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-26-14" name="__codelineno-26-14" href="#__codelineno-26-14"></a>
|
||||
<a id="__codelineno-26-15" name="__codelineno-26-15" href="#__codelineno-26-15"></a><span class="w"> </span><span class="n">pre</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span>
|
||||
<a id="__codelineno-26-16" name="__codelineno-26-16" href="#__codelineno-26-16"></a><span class="w"> </span><span class="c1"># 插入位置在 cur 的右子树中</span>
|
||||
<a id="__codelineno-26-17" name="__codelineno-26-17" href="#__codelineno-26-17"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-26-18" name="__codelineno-26-18" href="#__codelineno-26-18"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-26-19" name="__codelineno-26-19" href="#__codelineno-26-19"></a><span class="w"> </span><span class="c1"># 插入位置在 cur 的左子树中</span>
|
||||
<a id="__codelineno-26-20" name="__codelineno-26-20" href="#__codelineno-26-20"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-26-21" name="__codelineno-26-21" href="#__codelineno-26-21"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-26-22" name="__codelineno-26-22" href="#__codelineno-26-22"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-23" name="__codelineno-26-23" href="#__codelineno-26-23"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-24" name="__codelineno-26-24" href="#__codelineno-26-24"></a>
|
||||
<a id="__codelineno-26-25" name="__codelineno-26-25" href="#__codelineno-26-25"></a><span class="w"> </span><span class="c1"># 插入节点</span>
|
||||
<a id="__codelineno-26-26" name="__codelineno-26-26" href="#__codelineno-26-26"></a><span class="w"> </span><span class="n">node</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="no">TreeNode</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-27" name="__codelineno-26-27" href="#__codelineno-26-27"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">pre</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-26-28" name="__codelineno-26-28" href="#__codelineno-26-28"></a><span class="w"> </span><span class="n">pre</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span>
|
||||
<a id="__codelineno-26-29" name="__codelineno-26-29" href="#__codelineno-26-29"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-26-30" name="__codelineno-26-30" href="#__codelineno-26-30"></a><span class="w"> </span><span class="n">pre</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span>
|
||||
<a id="__codelineno-26-31" name="__codelineno-26-31" href="#__codelineno-26-31"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-32" name="__codelineno-26-32" href="#__codelineno-26-32"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -5227,7 +5277,57 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">binary_search_tree.rb</span><pre><span></span><code><a id="__codelineno-40-1" name="__codelineno-40-1" href="#__codelineno-40-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">BinarySearchTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">remove</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">binary_search_tree.rb</span><pre><span></span><code><a id="__codelineno-40-1" name="__codelineno-40-1" href="#__codelineno-40-1"></a><span class="c1">### 删除节点 ###</span>
|
||||
<a id="__codelineno-40-2" name="__codelineno-40-2" href="#__codelineno-40-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">remove</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
|
||||
<a id="__codelineno-40-3" name="__codelineno-40-3" href="#__codelineno-40-3"></a><span class="w"> </span><span class="c1"># 若树为空,直接提前返回</span>
|
||||
<a id="__codelineno-40-4" name="__codelineno-40-4" href="#__codelineno-40-4"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="vi">@root</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-40-5" name="__codelineno-40-5" href="#__codelineno-40-5"></a>
|
||||
<a id="__codelineno-40-6" name="__codelineno-40-6" href="#__codelineno-40-6"></a><span class="w"> </span><span class="c1"># 循环查找,越过叶节点后跳出</span>
|
||||
<a id="__codelineno-40-7" name="__codelineno-40-7" href="#__codelineno-40-7"></a><span class="w"> </span><span class="n">cur</span><span class="p">,</span><span class="w"> </span><span class="n">pre</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="vi">@root</span><span class="p">,</span><span class="w"> </span><span class="kp">nil</span>
|
||||
<a id="__codelineno-40-8" name="__codelineno-40-8" href="#__codelineno-40-8"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="o">!</span><span class="n">cur</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-40-9" name="__codelineno-40-9" href="#__codelineno-40-9"></a><span class="w"> </span><span class="c1"># 找到待删除节点,跳出循环</span>
|
||||
<a id="__codelineno-40-10" name="__codelineno-40-10" href="#__codelineno-40-10"></a><span class="w"> </span><span class="k">break</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-40-11" name="__codelineno-40-11" href="#__codelineno-40-11"></a>
|
||||
<a id="__codelineno-40-12" name="__codelineno-40-12" href="#__codelineno-40-12"></a><span class="w"> </span><span class="n">pre</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span>
|
||||
<a id="__codelineno-40-13" name="__codelineno-40-13" href="#__codelineno-40-13"></a><span class="w"> </span><span class="c1"># 待删除节点在 cur 的右子树中</span>
|
||||
<a id="__codelineno-40-14" name="__codelineno-40-14" href="#__codelineno-40-14"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-40-15" name="__codelineno-40-15" href="#__codelineno-40-15"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-40-16" name="__codelineno-40-16" href="#__codelineno-40-16"></a><span class="w"> </span><span class="c1"># 待删除节点在 cur 的左子树中</span>
|
||||
<a id="__codelineno-40-17" name="__codelineno-40-17" href="#__codelineno-40-17"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-40-18" name="__codelineno-40-18" href="#__codelineno-40-18"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-40-19" name="__codelineno-40-19" href="#__codelineno-40-19"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-40-20" name="__codelineno-40-20" href="#__codelineno-40-20"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-40-21" name="__codelineno-40-21" href="#__codelineno-40-21"></a><span class="w"> </span><span class="c1"># 若无待删除节点,则直接返回</span>
|
||||
<a id="__codelineno-40-22" name="__codelineno-40-22" href="#__codelineno-40-22"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-40-23" name="__codelineno-40-23" href="#__codelineno-40-23"></a>
|
||||
<a id="__codelineno-40-24" name="__codelineno-40-24" href="#__codelineno-40-24"></a><span class="w"> </span><span class="c1"># 子节点数量 = 0 or 1</span>
|
||||
<a id="__codelineno-40-25" name="__codelineno-40-25" href="#__codelineno-40-25"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">nil?</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">right</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-40-26" name="__codelineno-40-26" href="#__codelineno-40-26"></a><span class="w"> </span><span class="c1"># 当子节点数量 = 0 / 1 时, child = null / 该子节点</span>
|
||||
<a id="__codelineno-40-27" name="__codelineno-40-27" href="#__codelineno-40-27"></a><span class="w"> </span><span class="n">child</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-40-28" name="__codelineno-40-28" href="#__codelineno-40-28"></a><span class="w"> </span><span class="c1"># 删除节点 cur</span>
|
||||
<a id="__codelineno-40-29" name="__codelineno-40-29" href="#__codelineno-40-29"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="vi">@root</span>
|
||||
<a id="__codelineno-40-30" name="__codelineno-40-30" href="#__codelineno-40-30"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">pre</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">cur</span>
|
||||
<a id="__codelineno-40-31" name="__codelineno-40-31" href="#__codelineno-40-31"></a><span class="w"> </span><span class="n">pre</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">child</span>
|
||||
<a id="__codelineno-40-32" name="__codelineno-40-32" href="#__codelineno-40-32"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-40-33" name="__codelineno-40-33" href="#__codelineno-40-33"></a><span class="w"> </span><span class="n">pre</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">child</span>
|
||||
<a id="__codelineno-40-34" name="__codelineno-40-34" href="#__codelineno-40-34"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-40-35" name="__codelineno-40-35" href="#__codelineno-40-35"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-40-36" name="__codelineno-40-36" href="#__codelineno-40-36"></a><span class="w"> </span><span class="c1"># 若删除节点为根节点,则重新指定根节点</span>
|
||||
<a id="__codelineno-40-37" name="__codelineno-40-37" href="#__codelineno-40-37"></a><span class="w"> </span><span class="vi">@root</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">child</span>
|
||||
<a id="__codelineno-40-38" name="__codelineno-40-38" href="#__codelineno-40-38"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-40-39" name="__codelineno-40-39" href="#__codelineno-40-39"></a><span class="w"> </span><span class="c1"># 子节点数量 = 2</span>
|
||||
<a id="__codelineno-40-40" name="__codelineno-40-40" href="#__codelineno-40-40"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-40-41" name="__codelineno-40-41" href="#__codelineno-40-41"></a><span class="w"> </span><span class="c1"># 获取中序遍历中 cur 的下一个节点</span>
|
||||
<a id="__codelineno-40-42" name="__codelineno-40-42" href="#__codelineno-40-42"></a><span class="w"> </span><span class="n">tmp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-40-43" name="__codelineno-40-43" href="#__codelineno-40-43"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="o">!</span><span class="n">tmp</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-40-44" name="__codelineno-40-44" href="#__codelineno-40-44"></a><span class="w"> </span><span class="n">tmp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">tmp</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-40-45" name="__codelineno-40-45" href="#__codelineno-40-45"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-40-46" name="__codelineno-40-46" href="#__codelineno-40-46"></a><span class="w"> </span><span class="c1"># 递归删除节点 tmp</span>
|
||||
<a id="__codelineno-40-47" name="__codelineno-40-47" href="#__codelineno-40-47"></a><span class="w"> </span><span class="n">remove</span><span class="p">(</span><span class="n">tmp</span><span class="o">.</span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-40-48" name="__codelineno-40-48" href="#__codelineno-40-48"></a><span class="w"> </span><span class="c1"># 用 tmp 覆盖 cur</span>
|
||||
<a id="__codelineno-40-49" name="__codelineno-40-49" href="#__codelineno-40-49"></a><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">tmp</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-40-50" name="__codelineno-40-50" href="#__codelineno-40-50"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-40-51" name="__codelineno-40-51" href="#__codelineno-40-51"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
|
@ -4042,7 +4042,20 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">binary_tree_bfs.rb</span><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">level_order</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">binary_tree_bfs.rb</span><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a><span class="c1">### 层序遍历 ###</span>
|
||||
<a id="__codelineno-12-2" name="__codelineno-12-2" href="#__codelineno-12-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">level_order</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
|
||||
<a id="__codelineno-12-3" name="__codelineno-12-3" href="#__codelineno-12-3"></a><span class="w"> </span><span class="c1"># 初始化队列,加入根节点</span>
|
||||
<a id="__codelineno-12-4" name="__codelineno-12-4" href="#__codelineno-12-4"></a><span class="w"> </span><span class="n">queue</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[</span><span class="n">root</span><span class="o">]</span>
|
||||
<a id="__codelineno-12-5" name="__codelineno-12-5" href="#__codelineno-12-5"></a><span class="w"> </span><span class="c1"># 初始化一个列表,用于保存遍历序列</span>
|
||||
<a id="__codelineno-12-6" name="__codelineno-12-6" href="#__codelineno-12-6"></a><span class="w"> </span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[]</span>
|
||||
<a id="__codelineno-12-7" name="__codelineno-12-7" href="#__codelineno-12-7"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="o">!</span><span class="n">queue</span><span class="o">.</span><span class="n">empty?</span>
|
||||
<a id="__codelineno-12-8" name="__codelineno-12-8" href="#__codelineno-12-8"></a><span class="w"> </span><span class="n">node</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">queue</span><span class="o">.</span><span class="n">shift</span><span class="w"> </span><span class="c1"># 队列出队</span>
|
||||
<a id="__codelineno-12-9" name="__codelineno-12-9" href="#__codelineno-12-9"></a><span class="w"> </span><span class="n">res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="c1"># 保存节点值</span>
|
||||
<a id="__codelineno-12-10" name="__codelineno-12-10" href="#__codelineno-12-10"></a><span class="w"> </span><span class="n">queue</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="k">unless</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">nil?</span><span class="w"> </span><span class="c1"># 左子节点入队</span>
|
||||
<a id="__codelineno-12-11" name="__codelineno-12-11" href="#__codelineno-12-11"></a><span class="w"> </span><span class="n">queue</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="k">unless</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="o">.</span><span class="n">nil?</span><span class="w"> </span><span class="c1"># 右子节点入队</span>
|
||||
<a id="__codelineno-12-12" name="__codelineno-12-12" href="#__codelineno-12-12"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-12-13" name="__codelineno-12-13" href="#__codelineno-12-13"></a><span class="w"> </span><span class="n">res</span>
|
||||
<a id="__codelineno-12-14" name="__codelineno-12-14" href="#__codelineno-12-14"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -4487,9 +4500,25 @@
|
|||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">binary_tree_dfs.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">pre_order</span><span class="p">}</span>
|
||||
<a id="__codelineno-26-2" name="__codelineno-26-2" href="#__codelineno-26-2"></a>
|
||||
<a id="__codelineno-26-3" name="__codelineno-26-3" href="#__codelineno-26-3"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">in_order</span><span class="p">}</span>
|
||||
<a id="__codelineno-26-4" name="__codelineno-26-4" href="#__codelineno-26-4"></a>
|
||||
<a id="__codelineno-26-5" name="__codelineno-26-5" href="#__codelineno-26-5"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">post_order</span><span class="p">}</span>
|
||||
<a id="__codelineno-26-3" name="__codelineno-26-3" href="#__codelineno-26-3"></a><span class="c1">### 中序遍历 ###</span>
|
||||
<a id="__codelineno-26-4" name="__codelineno-26-4" href="#__codelineno-26-4"></a><span class="k">def</span><span class="w"> </span><span class="nf">in_order</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-5" name="__codelineno-26-5" href="#__codelineno-26-5"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">root</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-6" name="__codelineno-26-6" href="#__codelineno-26-6"></a>
|
||||
<a id="__codelineno-26-7" name="__codelineno-26-7" href="#__codelineno-26-7"></a><span class="w"> </span><span class="c1"># 访问优先级:左子树 -> 根节点 -> 右子树</span>
|
||||
<a id="__codelineno-26-8" name="__codelineno-26-8" href="#__codelineno-26-8"></a><span class="w"> </span><span class="n">in_order</span><span class="p">(</span><span class="n">root</span><span class="o">.</span><span class="n">left</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-9" name="__codelineno-26-9" href="#__codelineno-26-9"></a><span class="w"> </span><span class="vg">$res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">root</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-26-10" name="__codelineno-26-10" href="#__codelineno-26-10"></a><span class="w"> </span><span class="n">in_order</span><span class="p">(</span><span class="n">root</span><span class="o">.</span><span class="n">right</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-11" name="__codelineno-26-11" href="#__codelineno-26-11"></a><span class="k">end</span>
|
||||
<a id="__codelineno-26-12" name="__codelineno-26-12" href="#__codelineno-26-12"></a>
|
||||
<a id="__codelineno-26-13" name="__codelineno-26-13" href="#__codelineno-26-13"></a><span class="c1">### 后序遍历 ###</span>
|
||||
<a id="__codelineno-26-14" name="__codelineno-26-14" href="#__codelineno-26-14"></a><span class="k">def</span><span class="w"> </span><span class="nf">post_order</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-15" name="__codelineno-26-15" href="#__codelineno-26-15"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">root</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-16" name="__codelineno-26-16" href="#__codelineno-26-16"></a>
|
||||
<a id="__codelineno-26-17" name="__codelineno-26-17" href="#__codelineno-26-17"></a><span class="w"> </span><span class="c1"># 访问优先级:左子树 -> 右子树 -> 根节点</span>
|
||||
<a id="__codelineno-26-18" name="__codelineno-26-18" href="#__codelineno-26-18"></a><span class="w"> </span><span class="n">post_order</span><span class="p">(</span><span class="n">root</span><span class="o">.</span><span class="n">left</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-19" name="__codelineno-26-19" href="#__codelineno-26-19"></a><span class="w"> </span><span class="n">post_order</span><span class="p">(</span><span class="n">root</span><span class="o">.</span><span class="n">right</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-20" name="__codelineno-26-20" href="#__codelineno-26-20"></a><span class="w"> </span><span class="vg">$res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">root</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-26-21" name="__codelineno-26-21" href="#__codelineno-26-21"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
|
@ -3340,7 +3340,87 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">array_binary_tree.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">ArrayBinaryTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{}</span>
|
||||
<div class="highlight"><span class="filename">array_binary_tree.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="c1">### 数组表示下的二叉树类 ###</span>
|
||||
<a id="__codelineno-26-2" name="__codelineno-26-2" href="#__codelineno-26-2"></a><span class="k">class</span><span class="w"> </span><span class="nc">ArrayBinaryTree</span>
|
||||
<a id="__codelineno-26-3" name="__codelineno-26-3" href="#__codelineno-26-3"></a><span class="w"> </span><span class="c1">### 构造方法 ###</span>
|
||||
<a id="__codelineno-26-4" name="__codelineno-26-4" href="#__codelineno-26-4"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">initialize</span><span class="p">(</span><span class="n">arr</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-5" name="__codelineno-26-5" href="#__codelineno-26-5"></a><span class="w"> </span><span class="vi">@tree</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">arr</span><span class="o">.</span><span class="n">to_a</span>
|
||||
<a id="__codelineno-26-6" name="__codelineno-26-6" href="#__codelineno-26-6"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-7" name="__codelineno-26-7" href="#__codelineno-26-7"></a>
|
||||
<a id="__codelineno-26-8" name="__codelineno-26-8" href="#__codelineno-26-8"></a><span class="w"> </span><span class="c1">### 列表容量 ###</span>
|
||||
<a id="__codelineno-26-9" name="__codelineno-26-9" href="#__codelineno-26-9"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">size</span>
|
||||
<a id="__codelineno-26-10" name="__codelineno-26-10" href="#__codelineno-26-10"></a><span class="w"> </span><span class="vi">@tree</span><span class="o">.</span><span class="n">length</span>
|
||||
<a id="__codelineno-26-11" name="__codelineno-26-11" href="#__codelineno-26-11"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-12" name="__codelineno-26-12" href="#__codelineno-26-12"></a>
|
||||
<a id="__codelineno-26-13" name="__codelineno-26-13" href="#__codelineno-26-13"></a><span class="w"> </span><span class="c1">### 获取索引为 i 节点的值 ###</span>
|
||||
<a id="__codelineno-26-14" name="__codelineno-26-14" href="#__codelineno-26-14"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-15" name="__codelineno-26-15" href="#__codelineno-26-15"></a><span class="w"> </span><span class="c1"># 若索引越界,则返回 nil ,代表空位</span>
|
||||
<a id="__codelineno-26-16" name="__codelineno-26-16" href="#__codelineno-26-16"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="n">size</span>
|
||||
<a id="__codelineno-26-17" name="__codelineno-26-17" href="#__codelineno-26-17"></a>
|
||||
<a id="__codelineno-26-18" name="__codelineno-26-18" href="#__codelineno-26-18"></a><span class="w"> </span><span class="vi">@tree</span><span class="o">[</span><span class="n">i</span><span class="o">]</span>
|
||||
<a id="__codelineno-26-19" name="__codelineno-26-19" href="#__codelineno-26-19"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-20" name="__codelineno-26-20" href="#__codelineno-26-20"></a>
|
||||
<a id="__codelineno-26-21" name="__codelineno-26-21" href="#__codelineno-26-21"></a><span class="w"> </span><span class="c1">### 获取索引为 i 节点的左子节点的索引 ###</span>
|
||||
<a id="__codelineno-26-22" name="__codelineno-26-22" href="#__codelineno-26-22"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">left</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-23" name="__codelineno-26-23" href="#__codelineno-26-23"></a><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span>
|
||||
<a id="__codelineno-26-24" name="__codelineno-26-24" href="#__codelineno-26-24"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-25" name="__codelineno-26-25" href="#__codelineno-26-25"></a>
|
||||
<a id="__codelineno-26-26" name="__codelineno-26-26" href="#__codelineno-26-26"></a><span class="w"> </span><span class="c1">### 获取索引为 i 节点的右子节点的索引 ###</span>
|
||||
<a id="__codelineno-26-27" name="__codelineno-26-27" href="#__codelineno-26-27"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">right</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-28" name="__codelineno-26-28" href="#__codelineno-26-28"></a><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">2</span>
|
||||
<a id="__codelineno-26-29" name="__codelineno-26-29" href="#__codelineno-26-29"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-30" name="__codelineno-26-30" href="#__codelineno-26-30"></a>
|
||||
<a id="__codelineno-26-31" name="__codelineno-26-31" href="#__codelineno-26-31"></a><span class="w"> </span><span class="c1">### 获取索引为 i 节点的父节点的索引 ###</span>
|
||||
<a id="__codelineno-26-32" name="__codelineno-26-32" href="#__codelineno-26-32"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">parent</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-33" name="__codelineno-26-33" href="#__codelineno-26-33"></a><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="mi">2</span>
|
||||
<a id="__codelineno-26-34" name="__codelineno-26-34" href="#__codelineno-26-34"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-35" name="__codelineno-26-35" href="#__codelineno-26-35"></a>
|
||||
<a id="__codelineno-26-36" name="__codelineno-26-36" href="#__codelineno-26-36"></a><span class="w"> </span><span class="c1">### 层序遍历 ###</span>
|
||||
<a id="__codelineno-26-37" name="__codelineno-26-37" href="#__codelineno-26-37"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">level_order</span>
|
||||
<a id="__codelineno-26-38" name="__codelineno-26-38" href="#__codelineno-26-38"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[]</span>
|
||||
<a id="__codelineno-26-39" name="__codelineno-26-39" href="#__codelineno-26-39"></a>
|
||||
<a id="__codelineno-26-40" name="__codelineno-26-40" href="#__codelineno-26-40"></a><span class="w"> </span><span class="c1"># 直接遍历数组</span>
|
||||
<a id="__codelineno-26-41" name="__codelineno-26-41" href="#__codelineno-26-41"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="mi">0</span><span class="o">...</span><span class="n">size</span>
|
||||
<a id="__codelineno-26-42" name="__codelineno-26-42" href="#__codelineno-26-42"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="k">unless</span><span class="w"> </span><span class="n">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-43" name="__codelineno-26-43" href="#__codelineno-26-43"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-44" name="__codelineno-26-44" href="#__codelineno-26-44"></a>
|
||||
<a id="__codelineno-26-45" name="__codelineno-26-45" href="#__codelineno-26-45"></a><span class="w"> </span><span class="vi">@res</span>
|
||||
<a id="__codelineno-26-46" name="__codelineno-26-46" href="#__codelineno-26-46"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-47" name="__codelineno-26-47" href="#__codelineno-26-47"></a>
|
||||
<a id="__codelineno-26-48" name="__codelineno-26-48" href="#__codelineno-26-48"></a><span class="w"> </span><span class="c1">### 深度优先遍历 ###</span>
|
||||
<a id="__codelineno-26-49" name="__codelineno-26-49" href="#__codelineno-26-49"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">dfs</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">order</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-50" name="__codelineno-26-50" href="#__codelineno-26-50"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-51" name="__codelineno-26-51" href="#__codelineno-26-51"></a><span class="w"> </span><span class="c1"># 前序遍历</span>
|
||||
<a id="__codelineno-26-52" name="__codelineno-26-52" href="#__codelineno-26-52"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">order</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="ss">:pre</span>
|
||||
<a id="__codelineno-26-53" name="__codelineno-26-53" href="#__codelineno-26-53"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">left</span><span class="p">(</span><span class="n">i</span><span class="p">),</span><span class="w"> </span><span class="n">order</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-54" name="__codelineno-26-54" href="#__codelineno-26-54"></a><span class="w"> </span><span class="c1"># 中序遍历</span>
|
||||
<a id="__codelineno-26-55" name="__codelineno-26-55" href="#__codelineno-26-55"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">order</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="ss">:in</span>
|
||||
<a id="__codelineno-26-56" name="__codelineno-26-56" href="#__codelineno-26-56"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">right</span><span class="p">(</span><span class="n">i</span><span class="p">),</span><span class="w"> </span><span class="n">order</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-57" name="__codelineno-26-57" href="#__codelineno-26-57"></a><span class="w"> </span><span class="c1"># 后序遍历</span>
|
||||
<a id="__codelineno-26-58" name="__codelineno-26-58" href="#__codelineno-26-58"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">val</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">order</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="ss">:post</span>
|
||||
<a id="__codelineno-26-59" name="__codelineno-26-59" href="#__codelineno-26-59"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-60" name="__codelineno-26-60" href="#__codelineno-26-60"></a>
|
||||
<a id="__codelineno-26-61" name="__codelineno-26-61" href="#__codelineno-26-61"></a><span class="w"> </span><span class="c1">### 前序遍历 ###</span>
|
||||
<a id="__codelineno-26-62" name="__codelineno-26-62" href="#__codelineno-26-62"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">pre_order</span>
|
||||
<a id="__codelineno-26-63" name="__codelineno-26-63" href="#__codelineno-26-63"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[]</span>
|
||||
<a id="__codelineno-26-64" name="__codelineno-26-64" href="#__codelineno-26-64"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="ss">:pre</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-65" name="__codelineno-26-65" href="#__codelineno-26-65"></a><span class="w"> </span><span class="vi">@res</span>
|
||||
<a id="__codelineno-26-66" name="__codelineno-26-66" href="#__codelineno-26-66"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-67" name="__codelineno-26-67" href="#__codelineno-26-67"></a>
|
||||
<a id="__codelineno-26-68" name="__codelineno-26-68" href="#__codelineno-26-68"></a><span class="w"> </span><span class="c1">### 中序遍历 ###</span>
|
||||
<a id="__codelineno-26-69" name="__codelineno-26-69" href="#__codelineno-26-69"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">in_order</span>
|
||||
<a id="__codelineno-26-70" name="__codelineno-26-70" href="#__codelineno-26-70"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[]</span>
|
||||
<a id="__codelineno-26-71" name="__codelineno-26-71" href="#__codelineno-26-71"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="ss">:in</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-72" name="__codelineno-26-72" href="#__codelineno-26-72"></a><span class="w"> </span><span class="vi">@res</span>
|
||||
<a id="__codelineno-26-73" name="__codelineno-26-73" href="#__codelineno-26-73"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-74" name="__codelineno-26-74" href="#__codelineno-26-74"></a>
|
||||
<a id="__codelineno-26-75" name="__codelineno-26-75" href="#__codelineno-26-75"></a><span class="w"> </span><span class="c1">### 后序遍历 ###</span>
|
||||
<a id="__codelineno-26-76" name="__codelineno-26-76" href="#__codelineno-26-76"></a><span class="w"> </span><span class="k">def</span><span class="w"> </span><span class="nf">post_order</span>
|
||||
<a id="__codelineno-26-77" name="__codelineno-26-77" href="#__codelineno-26-77"></a><span class="w"> </span><span class="vi">@res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[]</span>
|
||||
<a id="__codelineno-26-78" name="__codelineno-26-78" href="#__codelineno-26-78"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="ss">:post</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-79" name="__codelineno-26-79" href="#__codelineno-26-79"></a><span class="w"> </span><span class="vi">@res</span>
|
||||
<a id="__codelineno-26-80" name="__codelineno-26-80" href="#__codelineno-26-80"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-81" name="__codelineno-26-81" href="#__codelineno-26-81"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
|
@ -2778,9 +2778,19 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">height</span><span class="p">}</span>
|
||||
<a id="__codelineno-26-2" name="__codelineno-26-2" href="#__codelineno-26-2"></a>
|
||||
<a id="__codelineno-26-3" name="__codelineno-26-3" href="#__codelineno-26-3"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">update_height</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="c1">### 获取节点高度 ###</span>
|
||||
<a id="__codelineno-26-2" name="__codelineno-26-2" href="#__codelineno-26-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">height</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-3" name="__codelineno-26-3" href="#__codelineno-26-3"></a><span class="w"> </span><span class="c1"># 空节点高度为 -1 ,叶节点高度为 0</span>
|
||||
<a id="__codelineno-26-4" name="__codelineno-26-4" href="#__codelineno-26-4"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">height</span><span class="w"> </span><span class="k">unless</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-5" name="__codelineno-26-5" href="#__codelineno-26-5"></a>
|
||||
<a id="__codelineno-26-6" name="__codelineno-26-6" href="#__codelineno-26-6"></a><span class="w"> </span><span class="o">-</span><span class="mi">1</span>
|
||||
<a id="__codelineno-26-7" name="__codelineno-26-7" href="#__codelineno-26-7"></a><span class="k">end</span>
|
||||
<a id="__codelineno-26-8" name="__codelineno-26-8" href="#__codelineno-26-8"></a>
|
||||
<a id="__codelineno-26-9" name="__codelineno-26-9" href="#__codelineno-26-9"></a><span class="c1">### 更新节点高度 ###</span>
|
||||
<a id="__codelineno-26-10" name="__codelineno-26-10" href="#__codelineno-26-10"></a><span class="k">def</span><span class="w"> </span><span class="nf">update_height</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-11" name="__codelineno-26-11" href="#__codelineno-26-11"></a><span class="w"> </span><span class="c1"># 节点高度等于最高子树高度 + 1</span>
|
||||
<a id="__codelineno-26-12" name="__codelineno-26-12" href="#__codelineno-26-12"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">height</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[</span><span class="n">height</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="p">),</span><span class="w"> </span><span class="n">height</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">)</span><span class="o">].</span><span class="n">max</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span>
|
||||
<a id="__codelineno-26-13" name="__codelineno-26-13" href="#__codelineno-26-13"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -2935,7 +2945,14 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-40-1" name="__codelineno-40-1" href="#__codelineno-40-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">balance_factor</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-40-1" name="__codelineno-40-1" href="#__codelineno-40-1"></a><span class="c1">### 获取平衡因子 ###</span>
|
||||
<a id="__codelineno-40-2" name="__codelineno-40-2" href="#__codelineno-40-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">balance_factor</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-40-3" name="__codelineno-40-3" href="#__codelineno-40-3"></a><span class="w"> </span><span class="c1"># 空节点平衡因子为 0</span>
|
||||
<a id="__codelineno-40-4" name="__codelineno-40-4" href="#__codelineno-40-4"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-40-5" name="__codelineno-40-5" href="#__codelineno-40-5"></a>
|
||||
<a id="__codelineno-40-6" name="__codelineno-40-6" href="#__codelineno-40-6"></a><span class="w"> </span><span class="c1"># 节点平衡因子 = 左子树高度 - 右子树高度</span>
|
||||
<a id="__codelineno-40-7" name="__codelineno-40-7" href="#__codelineno-40-7"></a><span class="w"> </span><span class="n">height</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="p">)</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">height</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">)</span>
|
||||
<a id="__codelineno-40-8" name="__codelineno-40-8" href="#__codelineno-40-8"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -3182,7 +3199,19 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-54-1" name="__codelineno-54-1" href="#__codelineno-54-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">right_rotate</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-54-1" name="__codelineno-54-1" href="#__codelineno-54-1"></a><span class="c1">### 右旋操作 ###</span>
|
||||
<a id="__codelineno-54-2" name="__codelineno-54-2" href="#__codelineno-54-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">right_rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-54-3" name="__codelineno-54-3" href="#__codelineno-54-3"></a><span class="w"> </span><span class="n">child</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-54-4" name="__codelineno-54-4" href="#__codelineno-54-4"></a><span class="w"> </span><span class="n">grand_child</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">child</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-54-5" name="__codelineno-54-5" href="#__codelineno-54-5"></a><span class="w"> </span><span class="c1"># 以 child 为原点,将 node 向右旋转</span>
|
||||
<a id="__codelineno-54-6" name="__codelineno-54-6" href="#__codelineno-54-6"></a><span class="w"> </span><span class="n">child</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span>
|
||||
<a id="__codelineno-54-7" name="__codelineno-54-7" href="#__codelineno-54-7"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">grand_child</span>
|
||||
<a id="__codelineno-54-8" name="__codelineno-54-8" href="#__codelineno-54-8"></a><span class="w"> </span><span class="c1"># 更新节点高度</span>
|
||||
<a id="__codelineno-54-9" name="__codelineno-54-9" href="#__codelineno-54-9"></a><span class="w"> </span><span class="n">update_height</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-54-10" name="__codelineno-54-10" href="#__codelineno-54-10"></a><span class="w"> </span><span class="n">update_height</span><span class="p">(</span><span class="n">child</span><span class="p">)</span>
|
||||
<a id="__codelineno-54-11" name="__codelineno-54-11" href="#__codelineno-54-11"></a><span class="w"> </span><span class="c1"># 返回旋转后子树的根节点</span>
|
||||
<a id="__codelineno-54-12" name="__codelineno-54-12" href="#__codelineno-54-12"></a><span class="w"> </span><span class="n">child</span>
|
||||
<a id="__codelineno-54-13" name="__codelineno-54-13" href="#__codelineno-54-13"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -3413,7 +3442,19 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-68-1" name="__codelineno-68-1" href="#__codelineno-68-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">left_rotate</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-68-1" name="__codelineno-68-1" href="#__codelineno-68-1"></a><span class="c1">### 左旋操作 ###</span>
|
||||
<a id="__codelineno-68-2" name="__codelineno-68-2" href="#__codelineno-68-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">left_rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-68-3" name="__codelineno-68-3" href="#__codelineno-68-3"></a><span class="w"> </span><span class="n">child</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-68-4" name="__codelineno-68-4" href="#__codelineno-68-4"></a><span class="w"> </span><span class="n">grand_child</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">child</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-68-5" name="__codelineno-68-5" href="#__codelineno-68-5"></a><span class="w"> </span><span class="c1"># 以 child 为原点,将 node 向左旋转</span>
|
||||
<a id="__codelineno-68-6" name="__codelineno-68-6" href="#__codelineno-68-6"></a><span class="w"> </span><span class="n">child</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span>
|
||||
<a id="__codelineno-68-7" name="__codelineno-68-7" href="#__codelineno-68-7"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">grand_child</span>
|
||||
<a id="__codelineno-68-8" name="__codelineno-68-8" href="#__codelineno-68-8"></a><span class="w"> </span><span class="c1"># 更新节点高度</span>
|
||||
<a id="__codelineno-68-9" name="__codelineno-68-9" href="#__codelineno-68-9"></a><span class="w"> </span><span class="n">update_height</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-68-10" name="__codelineno-68-10" href="#__codelineno-68-10"></a><span class="w"> </span><span class="n">update_height</span><span class="p">(</span><span class="n">child</span><span class="p">)</span>
|
||||
<a id="__codelineno-68-11" name="__codelineno-68-11" href="#__codelineno-68-11"></a><span class="w"> </span><span class="c1"># 返回旋转后子树的根节点</span>
|
||||
<a id="__codelineno-68-12" name="__codelineno-68-12" href="#__codelineno-68-12"></a><span class="w"> </span><span class="n">child</span>
|
||||
<a id="__codelineno-68-13" name="__codelineno-68-13" href="#__codelineno-68-13"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -3874,7 +3915,34 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-82-1" name="__codelineno-82-1" href="#__codelineno-82-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">rotate</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-82-1" name="__codelineno-82-1" href="#__codelineno-82-1"></a><span class="c1">### 执行旋转操作,使该子树重新恢复平衡 ###</span>
|
||||
<a id="__codelineno-82-2" name="__codelineno-82-2" href="#__codelineno-82-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-3" name="__codelineno-82-3" href="#__codelineno-82-3"></a><span class="w"> </span><span class="c1"># 获取节点 node 的平衡因子</span>
|
||||
<a id="__codelineno-82-4" name="__codelineno-82-4" href="#__codelineno-82-4"></a><span class="w"> </span><span class="n">balance_factor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">balance_factor</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-5" name="__codelineno-82-5" href="#__codelineno-82-5"></a><span class="w"> </span><span class="c1"># 左遍树</span>
|
||||
<a id="__codelineno-82-6" name="__codelineno-82-6" href="#__codelineno-82-6"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">balance_factor</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="mi">1</span>
|
||||
<a id="__codelineno-82-7" name="__codelineno-82-7" href="#__codelineno-82-7"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">balance_factor</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="p">)</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="mi">0</span>
|
||||
<a id="__codelineno-82-8" name="__codelineno-82-8" href="#__codelineno-82-8"></a><span class="w"> </span><span class="c1"># 右旋</span>
|
||||
<a id="__codelineno-82-9" name="__codelineno-82-9" href="#__codelineno-82-9"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">right_rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-10" name="__codelineno-82-10" href="#__codelineno-82-10"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-82-11" name="__codelineno-82-11" href="#__codelineno-82-11"></a><span class="w"> </span><span class="c1"># 先左旋后右旋</span>
|
||||
<a id="__codelineno-82-12" name="__codelineno-82-12" href="#__codelineno-82-12"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">left_rotate</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-13" name="__codelineno-82-13" href="#__codelineno-82-13"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">right_rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-14" name="__codelineno-82-14" href="#__codelineno-82-14"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-82-15" name="__codelineno-82-15" href="#__codelineno-82-15"></a><span class="w"> </span><span class="c1"># 右遍树</span>
|
||||
<a id="__codelineno-82-16" name="__codelineno-82-16" href="#__codelineno-82-16"></a><span class="w"> </span><span class="k">elsif</span><span class="w"> </span><span class="n">balance_factor</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span>
|
||||
<a id="__codelineno-82-17" name="__codelineno-82-17" href="#__codelineno-82-17"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">balance_factor</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">)</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="mi">0</span>
|
||||
<a id="__codelineno-82-18" name="__codelineno-82-18" href="#__codelineno-82-18"></a><span class="w"> </span><span class="c1"># 左旋</span>
|
||||
<a id="__codelineno-82-19" name="__codelineno-82-19" href="#__codelineno-82-19"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">left_rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-20" name="__codelineno-82-20" href="#__codelineno-82-20"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-82-21" name="__codelineno-82-21" href="#__codelineno-82-21"></a><span class="w"> </span><span class="c1"># 先右旋后左旋</span>
|
||||
<a id="__codelineno-82-22" name="__codelineno-82-22" href="#__codelineno-82-22"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">right_rotate</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-23" name="__codelineno-82-23" href="#__codelineno-82-23"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">left_rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-82-24" name="__codelineno-82-24" href="#__codelineno-82-24"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-82-25" name="__codelineno-82-25" href="#__codelineno-82-25"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-82-26" name="__codelineno-82-26" href="#__codelineno-82-26"></a><span class="w"> </span><span class="c1"># 平衡树,无须旋转,直接返回</span>
|
||||
<a id="__codelineno-82-27" name="__codelineno-82-27" href="#__codelineno-82-27"></a><span class="w"> </span><span class="n">node</span>
|
||||
<a id="__codelineno-82-28" name="__codelineno-82-28" href="#__codelineno-82-28"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -4238,9 +4306,28 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-96-1" name="__codelineno-96-1" href="#__codelineno-96-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">insert</span><span class="p">}</span>
|
||||
<a id="__codelineno-96-2" name="__codelineno-96-2" href="#__codelineno-96-2"></a>
|
||||
<a id="__codelineno-96-3" name="__codelineno-96-3" href="#__codelineno-96-3"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">insert_helper</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-96-1" name="__codelineno-96-1" href="#__codelineno-96-1"></a><span class="c1">### 插入节点 ###</span>
|
||||
<a id="__codelineno-96-2" name="__codelineno-96-2" href="#__codelineno-96-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">insert</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-3" name="__codelineno-96-3" href="#__codelineno-96-3"></a><span class="w"> </span><span class="vi">@root</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">insert_helper</span><span class="p">(</span><span class="vi">@root</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-4" name="__codelineno-96-4" href="#__codelineno-96-4"></a><span class="k">end</span>
|
||||
<a id="__codelineno-96-5" name="__codelineno-96-5" href="#__codelineno-96-5"></a>
|
||||
<a id="__codelineno-96-6" name="__codelineno-96-6" href="#__codelineno-96-6"></a><span class="c1">### 递归插入节点(辅助方法)###</span>
|
||||
<a id="__codelineno-96-7" name="__codelineno-96-7" href="#__codelineno-96-7"></a><span class="k">def</span><span class="w"> </span><span class="nf">insert_helper</span><span class="p">(</span><span class="n">node</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-8" name="__codelineno-96-8" href="#__codelineno-96-8"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="no">TreeNode</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">val</span><span class="p">)</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-96-9" name="__codelineno-96-9" href="#__codelineno-96-9"></a><span class="w"> </span><span class="c1"># 1. 查找插入位置并插入节点</span>
|
||||
<a id="__codelineno-96-10" name="__codelineno-96-10" href="#__codelineno-96-10"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">val</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-96-11" name="__codelineno-96-11" href="#__codelineno-96-11"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">insert_helper</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-12" name="__codelineno-96-12" href="#__codelineno-96-12"></a><span class="w"> </span><span class="k">elsif</span><span class="w"> </span><span class="n">val</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-96-13" name="__codelineno-96-13" href="#__codelineno-96-13"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">insert_helper</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-14" name="__codelineno-96-14" href="#__codelineno-96-14"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-96-15" name="__codelineno-96-15" href="#__codelineno-96-15"></a><span class="w"> </span><span class="c1"># 重复节点不插入,直接返回</span>
|
||||
<a id="__codelineno-96-16" name="__codelineno-96-16" href="#__codelineno-96-16"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">node</span>
|
||||
<a id="__codelineno-96-17" name="__codelineno-96-17" href="#__codelineno-96-17"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-96-18" name="__codelineno-96-18" href="#__codelineno-96-18"></a><span class="w"> </span><span class="c1"># 更新节点高度</span>
|
||||
<a id="__codelineno-96-19" name="__codelineno-96-19" href="#__codelineno-96-19"></a><span class="w"> </span><span class="n">update_height</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-20" name="__codelineno-96-20" href="#__codelineno-96-20"></a><span class="w"> </span><span class="c1"># 2. 执行旋转操作,使该子树重新恢复平衡</span>
|
||||
<a id="__codelineno-96-21" name="__codelineno-96-21" href="#__codelineno-96-21"></a><span class="w"> </span><span class="n">rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-96-22" name="__codelineno-96-22" href="#__codelineno-96-22"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -4813,9 +4900,41 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-110-1" name="__codelineno-110-1" href="#__codelineno-110-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">remove</span><span class="p">}</span>
|
||||
<a id="__codelineno-110-2" name="__codelineno-110-2" href="#__codelineno-110-2"></a>
|
||||
<a id="__codelineno-110-3" name="__codelineno-110-3" href="#__codelineno-110-3"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">AVLTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">remove_helper</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">avl_tree.rb</span><pre><span></span><code><a id="__codelineno-110-1" name="__codelineno-110-1" href="#__codelineno-110-1"></a><span class="c1">### 删除节点 ###</span>
|
||||
<a id="__codelineno-110-2" name="__codelineno-110-2" href="#__codelineno-110-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">remove</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-3" name="__codelineno-110-3" href="#__codelineno-110-3"></a><span class="w"> </span><span class="vi">@root</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">remove_helper</span><span class="p">(</span><span class="vi">@root</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-4" name="__codelineno-110-4" href="#__codelineno-110-4"></a><span class="k">end</span>
|
||||
<a id="__codelineno-110-5" name="__codelineno-110-5" href="#__codelineno-110-5"></a>
|
||||
<a id="__codelineno-110-6" name="__codelineno-110-6" href="#__codelineno-110-6"></a><span class="c1">### 递归删除节点(辅助方法)###</span>
|
||||
<a id="__codelineno-110-7" name="__codelineno-110-7" href="#__codelineno-110-7"></a><span class="k">def</span><span class="w"> </span><span class="nf">remove_helper</span><span class="p">(</span><span class="n">node</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-8" name="__codelineno-110-8" href="#__codelineno-110-8"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-110-9" name="__codelineno-110-9" href="#__codelineno-110-9"></a><span class="w"> </span><span class="c1"># 1. 查找节点并删除</span>
|
||||
<a id="__codelineno-110-10" name="__codelineno-110-10" href="#__codelineno-110-10"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">val</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-110-11" name="__codelineno-110-11" href="#__codelineno-110-11"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">remove_helper</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-12" name="__codelineno-110-12" href="#__codelineno-110-12"></a><span class="w"> </span><span class="k">elsif</span><span class="w"> </span><span class="n">val</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-110-13" name="__codelineno-110-13" href="#__codelineno-110-13"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">remove_helper</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-14" name="__codelineno-110-14" href="#__codelineno-110-14"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-110-15" name="__codelineno-110-15" href="#__codelineno-110-15"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">nil?</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-110-16" name="__codelineno-110-16" href="#__codelineno-110-16"></a><span class="w"> </span><span class="n">child</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-110-17" name="__codelineno-110-17" href="#__codelineno-110-17"></a><span class="w"> </span><span class="c1"># 子节点数量 = 0 ,直接删除 node 并返回</span>
|
||||
<a id="__codelineno-110-18" name="__codelineno-110-18" href="#__codelineno-110-18"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">child</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-110-19" name="__codelineno-110-19" href="#__codelineno-110-19"></a><span class="w"> </span><span class="c1"># 子节点数量 = 1 ,直接删除 node</span>
|
||||
<a id="__codelineno-110-20" name="__codelineno-110-20" href="#__codelineno-110-20"></a><span class="w"> </span><span class="n">node</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">child</span>
|
||||
<a id="__codelineno-110-21" name="__codelineno-110-21" href="#__codelineno-110-21"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-110-22" name="__codelineno-110-22" href="#__codelineno-110-22"></a><span class="w"> </span><span class="c1"># 子节点数量 = 2 ,则将中序遍历的下个节点删除,并用该节点替换当前节点</span>
|
||||
<a id="__codelineno-110-23" name="__codelineno-110-23" href="#__codelineno-110-23"></a><span class="w"> </span><span class="n">temp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-110-24" name="__codelineno-110-24" href="#__codelineno-110-24"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="o">!</span><span class="n">temp</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-110-25" name="__codelineno-110-25" href="#__codelineno-110-25"></a><span class="w"> </span><span class="n">temp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">temp</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-110-26" name="__codelineno-110-26" href="#__codelineno-110-26"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-110-27" name="__codelineno-110-27" href="#__codelineno-110-27"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">remove_helper</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="p">,</span><span class="w"> </span><span class="n">temp</span><span class="o">.</span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-28" name="__codelineno-110-28" href="#__codelineno-110-28"></a><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">temp</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-110-29" name="__codelineno-110-29" href="#__codelineno-110-29"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-110-30" name="__codelineno-110-30" href="#__codelineno-110-30"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-110-31" name="__codelineno-110-31" href="#__codelineno-110-31"></a><span class="w"> </span><span class="c1"># 更新节点高度</span>
|
||||
<a id="__codelineno-110-32" name="__codelineno-110-32" href="#__codelineno-110-32"></a><span class="w"> </span><span class="n">update_height</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-33" name="__codelineno-110-33" href="#__codelineno-110-33"></a><span class="w"> </span><span class="c1"># 2. 执行旋转操作,使该子树重新恢复平衡</span>
|
||||
<a id="__codelineno-110-34" name="__codelineno-110-34" href="#__codelineno-110-34"></a><span class="w"> </span><span class="n">rotate</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
<a id="__codelineno-110-35" name="__codelineno-110-35" href="#__codelineno-110-35"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
|
@ -2523,7 +2523,26 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">binary_search_tree.rb</span><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">BinarySearchTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">search</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">binary_search_tree.rb</span><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a><span class="c1">### 查找节点 ###</span>
|
||||
<a id="__codelineno-12-2" name="__codelineno-12-2" href="#__codelineno-12-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">search</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
|
||||
<a id="__codelineno-12-3" name="__codelineno-12-3" href="#__codelineno-12-3"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="vi">@root</span>
|
||||
<a id="__codelineno-12-4" name="__codelineno-12-4" href="#__codelineno-12-4"></a>
|
||||
<a id="__codelineno-12-5" name="__codelineno-12-5" href="#__codelineno-12-5"></a><span class="w"> </span><span class="c1"># 循环查找,越过叶节点后跳出</span>
|
||||
<a id="__codelineno-12-6" name="__codelineno-12-6" href="#__codelineno-12-6"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="o">!</span><span class="n">cur</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-12-7" name="__codelineno-12-7" href="#__codelineno-12-7"></a><span class="w"> </span><span class="c1"># 目标节点在 cur 的右子树中</span>
|
||||
<a id="__codelineno-12-8" name="__codelineno-12-8" href="#__codelineno-12-8"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-12-9" name="__codelineno-12-9" href="#__codelineno-12-9"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-12-10" name="__codelineno-12-10" href="#__codelineno-12-10"></a><span class="w"> </span><span class="c1"># 目标节点在 cur 的左子树中</span>
|
||||
<a id="__codelineno-12-11" name="__codelineno-12-11" href="#__codelineno-12-11"></a><span class="w"> </span><span class="k">elsif</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-12-12" name="__codelineno-12-12" href="#__codelineno-12-12"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-12-13" name="__codelineno-12-13" href="#__codelineno-12-13"></a><span class="w"> </span><span class="c1"># 找到目标节点,跳出循环</span>
|
||||
<a id="__codelineno-12-14" name="__codelineno-12-14" href="#__codelineno-12-14"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-12-15" name="__codelineno-12-15" href="#__codelineno-12-15"></a><span class="w"> </span><span class="k">break</span>
|
||||
<a id="__codelineno-12-16" name="__codelineno-12-16" href="#__codelineno-12-16"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-12-17" name="__codelineno-12-17" href="#__codelineno-12-17"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-12-18" name="__codelineno-12-18" href="#__codelineno-12-18"></a>
|
||||
<a id="__codelineno-12-19" name="__codelineno-12-19" href="#__codelineno-12-19"></a><span class="w"> </span><span class="n">cur</span>
|
||||
<a id="__codelineno-12-20" name="__codelineno-12-20" href="#__codelineno-12-20"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -2954,7 +2973,38 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">binary_search_tree.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">BinarySearchTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">insert</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">binary_search_tree.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="c1">### 插入节点 ###</span>
|
||||
<a id="__codelineno-26-2" name="__codelineno-26-2" href="#__codelineno-26-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">insert</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-3" name="__codelineno-26-3" href="#__codelineno-26-3"></a><span class="w"> </span><span class="c1"># 若树为空,则初始化根节点</span>
|
||||
<a id="__codelineno-26-4" name="__codelineno-26-4" href="#__codelineno-26-4"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="vi">@root</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-5" name="__codelineno-26-5" href="#__codelineno-26-5"></a><span class="w"> </span><span class="vi">@root</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="no">TreeNode</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-6" name="__codelineno-26-6" href="#__codelineno-26-6"></a><span class="w"> </span><span class="k">return</span>
|
||||
<a id="__codelineno-26-7" name="__codelineno-26-7" href="#__codelineno-26-7"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-8" name="__codelineno-26-8" href="#__codelineno-26-8"></a>
|
||||
<a id="__codelineno-26-9" name="__codelineno-26-9" href="#__codelineno-26-9"></a><span class="w"> </span><span class="c1"># 循环查找,越过叶节点后跳出</span>
|
||||
<a id="__codelineno-26-10" name="__codelineno-26-10" href="#__codelineno-26-10"></a><span class="w"> </span><span class="n">cur</span><span class="p">,</span><span class="w"> </span><span class="n">pre</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="vi">@root</span><span class="p">,</span><span class="w"> </span><span class="kp">nil</span>
|
||||
<a id="__codelineno-26-11" name="__codelineno-26-11" href="#__codelineno-26-11"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="o">!</span><span class="n">cur</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-12" name="__codelineno-26-12" href="#__codelineno-26-12"></a><span class="w"> </span><span class="c1"># 找到重复节点,直接返回</span>
|
||||
<a id="__codelineno-26-13" name="__codelineno-26-13" href="#__codelineno-26-13"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-26-14" name="__codelineno-26-14" href="#__codelineno-26-14"></a>
|
||||
<a id="__codelineno-26-15" name="__codelineno-26-15" href="#__codelineno-26-15"></a><span class="w"> </span><span class="n">pre</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span>
|
||||
<a id="__codelineno-26-16" name="__codelineno-26-16" href="#__codelineno-26-16"></a><span class="w"> </span><span class="c1"># 插入位置在 cur 的右子树中</span>
|
||||
<a id="__codelineno-26-17" name="__codelineno-26-17" href="#__codelineno-26-17"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-26-18" name="__codelineno-26-18" href="#__codelineno-26-18"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-26-19" name="__codelineno-26-19" href="#__codelineno-26-19"></a><span class="w"> </span><span class="c1"># 插入位置在 cur 的左子树中</span>
|
||||
<a id="__codelineno-26-20" name="__codelineno-26-20" href="#__codelineno-26-20"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-26-21" name="__codelineno-26-21" href="#__codelineno-26-21"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-26-22" name="__codelineno-26-22" href="#__codelineno-26-22"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-23" name="__codelineno-26-23" href="#__codelineno-26-23"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-24" name="__codelineno-26-24" href="#__codelineno-26-24"></a>
|
||||
<a id="__codelineno-26-25" name="__codelineno-26-25" href="#__codelineno-26-25"></a><span class="w"> </span><span class="c1"># 插入节点</span>
|
||||
<a id="__codelineno-26-26" name="__codelineno-26-26" href="#__codelineno-26-26"></a><span class="w"> </span><span class="n">node</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="no">TreeNode</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-27" name="__codelineno-26-27" href="#__codelineno-26-27"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">pre</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-26-28" name="__codelineno-26-28" href="#__codelineno-26-28"></a><span class="w"> </span><span class="n">pre</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span>
|
||||
<a id="__codelineno-26-29" name="__codelineno-26-29" href="#__codelineno-26-29"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-26-30" name="__codelineno-26-30" href="#__codelineno-26-30"></a><span class="w"> </span><span class="n">pre</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span>
|
||||
<a id="__codelineno-26-31" name="__codelineno-26-31" href="#__codelineno-26-31"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-26-32" name="__codelineno-26-32" href="#__codelineno-26-32"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -3697,7 +3747,57 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">binary_search_tree.rb</span><pre><span></span><code><a id="__codelineno-40-1" name="__codelineno-40-1" href="#__codelineno-40-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{</span><span class="no">BinarySearchTree</span><span class="p">}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">remove</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">binary_search_tree.rb</span><pre><span></span><code><a id="__codelineno-40-1" name="__codelineno-40-1" href="#__codelineno-40-1"></a><span class="c1">### 删除节点 ###</span>
|
||||
<a id="__codelineno-40-2" name="__codelineno-40-2" href="#__codelineno-40-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">remove</span><span class="p">(</span><span class="n">num</span><span class="p">)</span>
|
||||
<a id="__codelineno-40-3" name="__codelineno-40-3" href="#__codelineno-40-3"></a><span class="w"> </span><span class="c1"># 若树为空,直接提前返回</span>
|
||||
<a id="__codelineno-40-4" name="__codelineno-40-4" href="#__codelineno-40-4"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="vi">@root</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-40-5" name="__codelineno-40-5" href="#__codelineno-40-5"></a>
|
||||
<a id="__codelineno-40-6" name="__codelineno-40-6" href="#__codelineno-40-6"></a><span class="w"> </span><span class="c1"># 循环查找,越过叶节点后跳出</span>
|
||||
<a id="__codelineno-40-7" name="__codelineno-40-7" href="#__codelineno-40-7"></a><span class="w"> </span><span class="n">cur</span><span class="p">,</span><span class="w"> </span><span class="n">pre</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="vi">@root</span><span class="p">,</span><span class="w"> </span><span class="kp">nil</span>
|
||||
<a id="__codelineno-40-8" name="__codelineno-40-8" href="#__codelineno-40-8"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="o">!</span><span class="n">cur</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-40-9" name="__codelineno-40-9" href="#__codelineno-40-9"></a><span class="w"> </span><span class="c1"># 找到待删除节点,跳出循环</span>
|
||||
<a id="__codelineno-40-10" name="__codelineno-40-10" href="#__codelineno-40-10"></a><span class="w"> </span><span class="k">break</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-40-11" name="__codelineno-40-11" href="#__codelineno-40-11"></a>
|
||||
<a id="__codelineno-40-12" name="__codelineno-40-12" href="#__codelineno-40-12"></a><span class="w"> </span><span class="n">pre</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span>
|
||||
<a id="__codelineno-40-13" name="__codelineno-40-13" href="#__codelineno-40-13"></a><span class="w"> </span><span class="c1"># 待删除节点在 cur 的右子树中</span>
|
||||
<a id="__codelineno-40-14" name="__codelineno-40-14" href="#__codelineno-40-14"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">num</span>
|
||||
<a id="__codelineno-40-15" name="__codelineno-40-15" href="#__codelineno-40-15"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-40-16" name="__codelineno-40-16" href="#__codelineno-40-16"></a><span class="w"> </span><span class="c1"># 待删除节点在 cur 的左子树中</span>
|
||||
<a id="__codelineno-40-17" name="__codelineno-40-17" href="#__codelineno-40-17"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-40-18" name="__codelineno-40-18" href="#__codelineno-40-18"></a><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-40-19" name="__codelineno-40-19" href="#__codelineno-40-19"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-40-20" name="__codelineno-40-20" href="#__codelineno-40-20"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-40-21" name="__codelineno-40-21" href="#__codelineno-40-21"></a><span class="w"> </span><span class="c1"># 若无待删除节点,则直接返回</span>
|
||||
<a id="__codelineno-40-22" name="__codelineno-40-22" href="#__codelineno-40-22"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-40-23" name="__codelineno-40-23" href="#__codelineno-40-23"></a>
|
||||
<a id="__codelineno-40-24" name="__codelineno-40-24" href="#__codelineno-40-24"></a><span class="w"> </span><span class="c1"># 子节点数量 = 0 or 1</span>
|
||||
<a id="__codelineno-40-25" name="__codelineno-40-25" href="#__codelineno-40-25"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">nil?</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">right</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-40-26" name="__codelineno-40-26" href="#__codelineno-40-26"></a><span class="w"> </span><span class="c1"># 当子节点数量 = 0 / 1 时, child = null / 该子节点</span>
|
||||
<a id="__codelineno-40-27" name="__codelineno-40-27" href="#__codelineno-40-27"></a><span class="w"> </span><span class="n">child</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-40-28" name="__codelineno-40-28" href="#__codelineno-40-28"></a><span class="w"> </span><span class="c1"># 删除节点 cur</span>
|
||||
<a id="__codelineno-40-29" name="__codelineno-40-29" href="#__codelineno-40-29"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">cur</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="vi">@root</span>
|
||||
<a id="__codelineno-40-30" name="__codelineno-40-30" href="#__codelineno-40-30"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">pre</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">cur</span>
|
||||
<a id="__codelineno-40-31" name="__codelineno-40-31" href="#__codelineno-40-31"></a><span class="w"> </span><span class="n">pre</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">child</span>
|
||||
<a id="__codelineno-40-32" name="__codelineno-40-32" href="#__codelineno-40-32"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-40-33" name="__codelineno-40-33" href="#__codelineno-40-33"></a><span class="w"> </span><span class="n">pre</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">child</span>
|
||||
<a id="__codelineno-40-34" name="__codelineno-40-34" href="#__codelineno-40-34"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-40-35" name="__codelineno-40-35" href="#__codelineno-40-35"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-40-36" name="__codelineno-40-36" href="#__codelineno-40-36"></a><span class="w"> </span><span class="c1"># 若删除节点为根节点,则重新指定根节点</span>
|
||||
<a id="__codelineno-40-37" name="__codelineno-40-37" href="#__codelineno-40-37"></a><span class="w"> </span><span class="vi">@root</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">child</span>
|
||||
<a id="__codelineno-40-38" name="__codelineno-40-38" href="#__codelineno-40-38"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-40-39" name="__codelineno-40-39" href="#__codelineno-40-39"></a><span class="w"> </span><span class="c1"># 子节点数量 = 2</span>
|
||||
<a id="__codelineno-40-40" name="__codelineno-40-40" href="#__codelineno-40-40"></a><span class="w"> </span><span class="k">else</span>
|
||||
<a id="__codelineno-40-41" name="__codelineno-40-41" href="#__codelineno-40-41"></a><span class="w"> </span><span class="c1"># 获取中序遍历中 cur 的下一个节点</span>
|
||||
<a id="__codelineno-40-42" name="__codelineno-40-42" href="#__codelineno-40-42"></a><span class="w"> </span><span class="n">tmp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">right</span>
|
||||
<a id="__codelineno-40-43" name="__codelineno-40-43" href="#__codelineno-40-43"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="o">!</span><span class="n">tmp</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-40-44" name="__codelineno-40-44" href="#__codelineno-40-44"></a><span class="w"> </span><span class="n">tmp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">tmp</span><span class="o">.</span><span class="n">left</span>
|
||||
<a id="__codelineno-40-45" name="__codelineno-40-45" href="#__codelineno-40-45"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-40-46" name="__codelineno-40-46" href="#__codelineno-40-46"></a><span class="w"> </span><span class="c1"># 递归删除节点 tmp</span>
|
||||
<a id="__codelineno-40-47" name="__codelineno-40-47" href="#__codelineno-40-47"></a><span class="w"> </span><span class="n">remove</span><span class="p">(</span><span class="n">tmp</span><span class="o">.</span><span class="n">val</span><span class="p">)</span>
|
||||
<a id="__codelineno-40-48" name="__codelineno-40-48" href="#__codelineno-40-48"></a><span class="w"> </span><span class="c1"># 用 tmp 覆盖 cur</span>
|
||||
<a id="__codelineno-40-49" name="__codelineno-40-49" href="#__codelineno-40-49"></a><span class="w"> </span><span class="n">cur</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">tmp</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-40-50" name="__codelineno-40-50" href="#__codelineno-40-50"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-40-51" name="__codelineno-40-51" href="#__codelineno-40-51"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
|
@ -2512,7 +2512,20 @@
|
|||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">binary_tree_bfs.rb</span><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">level_order</span><span class="p">}</span>
|
||||
<div class="highlight"><span class="filename">binary_tree_bfs.rb</span><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a><span class="c1">### 层序遍历 ###</span>
|
||||
<a id="__codelineno-12-2" name="__codelineno-12-2" href="#__codelineno-12-2"></a><span class="k">def</span><span class="w"> </span><span class="nf">level_order</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
|
||||
<a id="__codelineno-12-3" name="__codelineno-12-3" href="#__codelineno-12-3"></a><span class="w"> </span><span class="c1"># 初始化队列,加入根节点</span>
|
||||
<a id="__codelineno-12-4" name="__codelineno-12-4" href="#__codelineno-12-4"></a><span class="w"> </span><span class="n">queue</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[</span><span class="n">root</span><span class="o">]</span>
|
||||
<a id="__codelineno-12-5" name="__codelineno-12-5" href="#__codelineno-12-5"></a><span class="w"> </span><span class="c1"># 初始化一个列表,用于保存遍历序列</span>
|
||||
<a id="__codelineno-12-6" name="__codelineno-12-6" href="#__codelineno-12-6"></a><span class="w"> </span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">[]</span>
|
||||
<a id="__codelineno-12-7" name="__codelineno-12-7" href="#__codelineno-12-7"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="o">!</span><span class="n">queue</span><span class="o">.</span><span class="n">empty?</span>
|
||||
<a id="__codelineno-12-8" name="__codelineno-12-8" href="#__codelineno-12-8"></a><span class="w"> </span><span class="n">node</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">queue</span><span class="o">.</span><span class="n">shift</span><span class="w"> </span><span class="c1"># 队列出队</span>
|
||||
<a id="__codelineno-12-9" name="__codelineno-12-9" href="#__codelineno-12-9"></a><span class="w"> </span><span class="n">res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">val</span><span class="w"> </span><span class="c1"># 保存节点值</span>
|
||||
<a id="__codelineno-12-10" name="__codelineno-12-10" href="#__codelineno-12-10"></a><span class="w"> </span><span class="n">queue</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="w"> </span><span class="k">unless</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">left</span><span class="o">.</span><span class="n">nil?</span><span class="w"> </span><span class="c1"># 左子节点入队</span>
|
||||
<a id="__codelineno-12-11" name="__codelineno-12-11" href="#__codelineno-12-11"></a><span class="w"> </span><span class="n">queue</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="w"> </span><span class="k">unless</span><span class="w"> </span><span class="n">node</span><span class="o">.</span><span class="n">right</span><span class="o">.</span><span class="n">nil?</span><span class="w"> </span><span class="c1"># 右子节点入队</span>
|
||||
<a id="__codelineno-12-12" name="__codelineno-12-12" href="#__codelineno-12-12"></a><span class="w"> </span><span class="k">end</span>
|
||||
<a id="__codelineno-12-13" name="__codelineno-12-13" href="#__codelineno-12-13"></a><span class="w"> </span><span class="n">res</span>
|
||||
<a id="__codelineno-12-14" name="__codelineno-12-14" href="#__codelineno-12-14"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
@ -2957,9 +2970,25 @@
|
|||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">binary_tree_dfs.rb</span><pre><span></span><code><a id="__codelineno-26-1" name="__codelineno-26-1" href="#__codelineno-26-1"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">pre_order</span><span class="p">}</span>
|
||||
<a id="__codelineno-26-2" name="__codelineno-26-2" href="#__codelineno-26-2"></a>
|
||||
<a id="__codelineno-26-3" name="__codelineno-26-3" href="#__codelineno-26-3"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">in_order</span><span class="p">}</span>
|
||||
<a id="__codelineno-26-4" name="__codelineno-26-4" href="#__codelineno-26-4"></a>
|
||||
<a id="__codelineno-26-5" name="__codelineno-26-5" href="#__codelineno-26-5"></a><span class="o">[</span><span class="n">class</span><span class="o">]</span><span class="p">{}</span><span class="o">-[</span><span class="n">func</span><span class="o">]</span><span class="p">{</span><span class="n">post_order</span><span class="p">}</span>
|
||||
<a id="__codelineno-26-3" name="__codelineno-26-3" href="#__codelineno-26-3"></a><span class="c1">### 中序遍历 ###</span>
|
||||
<a id="__codelineno-26-4" name="__codelineno-26-4" href="#__codelineno-26-4"></a><span class="k">def</span><span class="w"> </span><span class="nf">in_order</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-5" name="__codelineno-26-5" href="#__codelineno-26-5"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">root</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-6" name="__codelineno-26-6" href="#__codelineno-26-6"></a>
|
||||
<a id="__codelineno-26-7" name="__codelineno-26-7" href="#__codelineno-26-7"></a><span class="w"> </span><span class="c1"># 访问优先级:左子树 -> 根节点 -> 右子树</span>
|
||||
<a id="__codelineno-26-8" name="__codelineno-26-8" href="#__codelineno-26-8"></a><span class="w"> </span><span class="n">in_order</span><span class="p">(</span><span class="n">root</span><span class="o">.</span><span class="n">left</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-9" name="__codelineno-26-9" href="#__codelineno-26-9"></a><span class="w"> </span><span class="vg">$res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">root</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-26-10" name="__codelineno-26-10" href="#__codelineno-26-10"></a><span class="w"> </span><span class="n">in_order</span><span class="p">(</span><span class="n">root</span><span class="o">.</span><span class="n">right</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-11" name="__codelineno-26-11" href="#__codelineno-26-11"></a><span class="k">end</span>
|
||||
<a id="__codelineno-26-12" name="__codelineno-26-12" href="#__codelineno-26-12"></a>
|
||||
<a id="__codelineno-26-13" name="__codelineno-26-13" href="#__codelineno-26-13"></a><span class="c1">### 后序遍历 ###</span>
|
||||
<a id="__codelineno-26-14" name="__codelineno-26-14" href="#__codelineno-26-14"></a><span class="k">def</span><span class="w"> </span><span class="nf">post_order</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-15" name="__codelineno-26-15" href="#__codelineno-26-15"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">root</span><span class="o">.</span><span class="n">nil?</span>
|
||||
<a id="__codelineno-26-16" name="__codelineno-26-16" href="#__codelineno-26-16"></a>
|
||||
<a id="__codelineno-26-17" name="__codelineno-26-17" href="#__codelineno-26-17"></a><span class="w"> </span><span class="c1"># 访问优先级:左子树 -> 右子树 -> 根节点</span>
|
||||
<a id="__codelineno-26-18" name="__codelineno-26-18" href="#__codelineno-26-18"></a><span class="w"> </span><span class="n">post_order</span><span class="p">(</span><span class="n">root</span><span class="o">.</span><span class="n">left</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-19" name="__codelineno-26-19" href="#__codelineno-26-19"></a><span class="w"> </span><span class="n">post_order</span><span class="p">(</span><span class="n">root</span><span class="o">.</span><span class="n">right</span><span class="p">)</span>
|
||||
<a id="__codelineno-26-20" name="__codelineno-26-20" href="#__codelineno-26-20"></a><span class="w"> </span><span class="vg">$res</span><span class="w"> </span><span class="o"><<</span><span class="w"> </span><span class="n">root</span><span class="o">.</span><span class="n">val</span>
|
||||
<a id="__codelineno-26-21" name="__codelineno-26-21" href="#__codelineno-26-21"></a><span class="k">end</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
File diff suppressed because one or more lines are too long
110
en/sitemap.xml
110
en/sitemap.xml
|
@ -2,277 +2,277 @@
|
|||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_array_and_linkedlist/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_array_and_linkedlist/array/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_array_and_linkedlist/linked_list/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_array_and_linkedlist/list/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_array_and_linkedlist/ram_and_cache/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_array_and_linkedlist/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_computational_complexity/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_computational_complexity/iteration_and_recursion/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_computational_complexity/performance_evaluation/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_computational_complexity/space_complexity/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_computational_complexity/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_computational_complexity/time_complexity/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_data_structure/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_data_structure/basic_data_types/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_data_structure/character_encoding/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_data_structure/classification_of_data_structure/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_data_structure/number_encoding/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_data_structure/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_graph/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_graph/graph/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_graph/graph_operations/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_graph/graph_traversal/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_graph/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_hashing/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_hashing/hash_algorithm/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_hashing/hash_collision/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_hashing/hash_map/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_hashing/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_heap/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_heap/build_heap/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_heap/heap/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_heap/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_heap/top_k/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_hello_algo/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_introduction/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_introduction/algorithms_are_everywhere/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_introduction/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_introduction/what_is_dsa/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_preface/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_preface/about_the_book/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_preface/suggestions/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_preface/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_stack_and_queue/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_stack_and_queue/deque/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_stack_and_queue/queue/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_stack_and_queue/stack/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_stack_and_queue/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_tree/array_representation_of_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_tree/avl_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_tree/binary_search_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_tree/binary_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_tree/binary_tree_traversal/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/en/chapter_tree/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
</urlset>
|
Binary file not shown.
File diff suppressed because one or more lines are too long
212
sitemap.xml
212
sitemap.xml
|
@ -2,532 +2,532 @@
|
|||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_appendix/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_appendix/contribution/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_appendix/installation/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_appendix/terminology/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/array/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/linked_list/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/list/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/ram_and_cache/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/backtracking_algorithm/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/n_queens_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/permutations_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/subset_sum_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/iteration_and_recursion/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/performance_evaluation/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/space_complexity/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/time_complexity/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/basic_data_types/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/character_encoding/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/classification_of_data_structure/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/number_encoding/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/binary_search_recur/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/build_binary_tree_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/divide_and_conquer/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/hanota_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/dp_problem_features/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/dp_solution_pipeline/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/edit_distance_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/intro_to_dynamic_programming/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/knapsack_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/unbounded_knapsack_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/graph/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/graph_operations/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/graph_traversal/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/fractional_knapsack_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/greedy_algorithm/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/max_capacity_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/max_product_cutting_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/hash_algorithm/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/hash_collision/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/hash_map/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/build_heap/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/heap/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/top_k/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hello_algo/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_introduction/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_introduction/algorithms_are_everywhere/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_introduction/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_introduction/what_is_dsa/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_paperbook/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_preface/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_preface/about_the_book/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_preface/suggestions/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_preface/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_reference/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/binary_search/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/binary_search_edge/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/binary_search_insertion/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/replace_linear_by_hashing/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/searching_algorithm_revisited/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/bubble_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/bucket_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/counting_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/heap_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/insertion_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/merge_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/quick_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/radix_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/selection_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/sorting_algorithm/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/deque/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/queue/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/stack/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/array_representation_of_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/avl_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/binary_search_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/binary_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/binary_tree_traversal/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
</urlset>
|
BIN
sitemap.xml.gz
BIN
sitemap.xml.gz
Binary file not shown.
|
@ -3468,18 +3468,27 @@
|
|||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#8-dart" class="md-nav__link">
|
||||
<a href="#8-typescript" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
8. Dart 環境
|
||||
8. TypeScript 環境
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#9-rust" class="md-nav__link">
|
||||
<a href="#9-dart" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
9. Rust 環境
|
||||
9. Dart 環境
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#10-rust" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
10. Rust 環境
|
||||
</span>
|
||||
</a>
|
||||
|
||||
|
@ -3714,18 +3723,27 @@
|
|||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#8-dart" class="md-nav__link">
|
||||
<a href="#8-typescript" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
8. Dart 環境
|
||||
8. TypeScript 環境
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#9-rust" class="md-nav__link">
|
||||
<a href="#9-dart" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
9. Rust 環境
|
||||
9. Dart 環境
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#10-rust" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
10. Rust 環境
|
||||
</span>
|
||||
</a>
|
||||
|
||||
|
@ -3819,16 +3837,21 @@
|
|||
</ol>
|
||||
<h3 id="7-javascript">7. JavaScript 環境<a class="headerlink" href="#7-javascript" title="Permanent link">¶</a></h3>
|
||||
<ol>
|
||||
<li>下載並安裝 <a href="https://nodejs.org/en/">node.js</a> 。</li>
|
||||
<li>在 VS Code 的擴充功能市場中搜索 <code>javascript</code> ,安裝 JavaScript (ES6) code snippets 。</li>
|
||||
<li>下載並安裝 <a href="https://nodejs.org/en/">Node.js</a> 。</li>
|
||||
<li>(可選)在 VS Code 的擴充功能市場中搜索 <code>Prettier</code> ,安裝程式碼格式化工具。</li>
|
||||
</ol>
|
||||
<h3 id="8-dart">8. Dart 環境<a class="headerlink" href="#8-dart" title="Permanent link">¶</a></h3>
|
||||
<h3 id="8-typescript">8. TypeScript 環境<a class="headerlink" href="#8-typescript" title="Permanent link">¶</a></h3>
|
||||
<ol>
|
||||
<li>同 JavaScript 環境安裝步驟。</li>
|
||||
<li>安裝 <a href="https://github.com/privatenumber/tsx?tab=readme-ov-file#global-installation">TypeScript Execute (tsx)</a> 。</li>
|
||||
<li>在 VS Code 的擴充功能市場中搜索 <code>typescript</code> ,安裝 <a href="https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors">Pretty TypeScript Errors</a> 。</li>
|
||||
</ol>
|
||||
<h3 id="9-dart">9. Dart 環境<a class="headerlink" href="#9-dart" title="Permanent link">¶</a></h3>
|
||||
<ol>
|
||||
<li>下載並安裝 <a href="https://dart.dev/get-dart">Dart</a> 。</li>
|
||||
<li>在 VS Code 的擴充功能市場中搜索 <code>dart</code> ,安裝 <a href="https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code">Dart</a> 。</li>
|
||||
</ol>
|
||||
<h3 id="9-rust">9. Rust 環境<a class="headerlink" href="#9-rust" title="Permanent link">¶</a></h3>
|
||||
<h3 id="10-rust">10. Rust 環境<a class="headerlink" href="#10-rust" title="Permanent link">¶</a></h3>
|
||||
<ol>
|
||||
<li>下載並安裝 <a href="https://www.rust-lang.org/tools/install">Rust</a> 。</li>
|
||||
<li>在 VS Code 的擴充功能市場中搜索 <code>rust</code> ,安裝 <a href="https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer">rust-analyzer</a> 。</li>
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2,527 +2,527 @@
|
|||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_appendix/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_appendix/contribution/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_appendix/installation/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_appendix/terminology/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_array_and_linkedlist/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_array_and_linkedlist/array/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_array_and_linkedlist/linked_list/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_array_and_linkedlist/list/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_array_and_linkedlist/ram_and_cache/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_array_and_linkedlist/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_backtracking/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_backtracking/backtracking_algorithm/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_backtracking/n_queens_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_backtracking/permutations_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_backtracking/subset_sum_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_backtracking/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_computational_complexity/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_computational_complexity/iteration_and_recursion/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_computational_complexity/performance_evaluation/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_computational_complexity/space_complexity/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_computational_complexity/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_computational_complexity/time_complexity/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_data_structure/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_data_structure/basic_data_types/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_data_structure/character_encoding/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_data_structure/classification_of_data_structure/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_data_structure/number_encoding/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_data_structure/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_divide_and_conquer/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_divide_and_conquer/binary_search_recur/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_divide_and_conquer/build_binary_tree_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_divide_and_conquer/divide_and_conquer/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_divide_and_conquer/hanota_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_divide_and_conquer/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_dynamic_programming/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_dynamic_programming/dp_problem_features/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_dynamic_programming/dp_solution_pipeline/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_dynamic_programming/edit_distance_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_dynamic_programming/intro_to_dynamic_programming/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_dynamic_programming/knapsack_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_dynamic_programming/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_dynamic_programming/unbounded_knapsack_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_graph/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_graph/graph/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_graph/graph_operations/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_graph/graph_traversal/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_graph/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_greedy/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_greedy/fractional_knapsack_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_greedy/greedy_algorithm/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_greedy/max_capacity_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_greedy/max_product_cutting_problem/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_greedy/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_hashing/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_hashing/hash_algorithm/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_hashing/hash_collision/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_hashing/hash_map/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_hashing/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_heap/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_heap/build_heap/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_heap/heap/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_heap/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_heap/top_k/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_hello_algo/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_introduction/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_introduction/algorithms_are_everywhere/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_introduction/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_introduction/what_is_dsa/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_preface/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_preface/about_the_book/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_preface/suggestions/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_preface/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_reference/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_searching/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_searching/binary_search/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_searching/binary_search_edge/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_searching/binary_search_insertion/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_searching/replace_linear_by_hashing/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_searching/searching_algorithm_revisited/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_searching/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_sorting/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_sorting/bubble_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_sorting/bucket_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_sorting/counting_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_sorting/heap_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_sorting/insertion_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_sorting/merge_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_sorting/quick_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_sorting/radix_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_sorting/selection_sort/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_sorting/sorting_algorithm/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_sorting/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_stack_and_queue/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_stack_and_queue/deque/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_stack_and_queue/queue/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_stack_and_queue/stack/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_stack_and_queue/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_tree/array_representation_of_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_tree/avl_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_tree/binary_search_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_tree/binary_tree/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_tree/binary_tree_traversal/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/zh-hant/chapter_tree/summary/</loc>
|
||||
<lastmod>2024-04-15</lastmod>
|
||||
<lastmod>2024-04-19</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
</urlset>
|
Binary file not shown.
Loading…
Reference in a new issue