mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 00:46:28 +08:00
deploy
This commit is contained in:
parent
226ed3efa9
commit
10cd7ac31d
15 changed files with 467 additions and 440 deletions
|
@ -3499,6 +3499,14 @@
|
|||
<td>balanced binary tree</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>AVL 树</td>
|
||||
<td>AVL tree</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>红黑树</td>
|
||||
<td>red-black tree</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>层序遍历</td>
|
||||
<td>level-order traversal</td>
|
||||
</tr>
|
||||
|
@ -3680,11 +3688,11 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td>全排列问题</td>
|
||||
<td>Permutations problem</td>
|
||||
<td>permutations problem</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>子集和问题</td>
|
||||
<td>Subset-sum problem</td>
|
||||
<td>subset-sum problem</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>N 皇后问题</td>
|
||||
|
|
|
@ -5251,7 +5251,7 @@
|
|||
<a id="__codelineno-82-69" name="__codelineno-82-69" href="#__codelineno-82-69"></a>
|
||||
<a id="__codelineno-82-70" name="__codelineno-82-70" href="#__codelineno-82-70"></a><span class="cm">/* 删除元素 */</span>
|
||||
<a id="__codelineno-82-71" name="__codelineno-82-71" href="#__codelineno-82-71"></a><span class="c1">// 注意:stdio.h 占用了 remove 关键词</span>
|
||||
<a id="__codelineno-82-72" name="__codelineno-82-72" href="#__codelineno-82-72"></a><span class="kt">int</span><span class="w"> </span><span class="nf">removeNum</span><span class="p">(</span><span class="n">MyList</span><span class="w"> </span><span class="o">*</span><span class="n">nums</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-82-72" name="__codelineno-82-72" href="#__codelineno-82-72"></a><span class="kt">int</span><span class="w"> </span><span class="nf">removeItem</span><span class="p">(</span><span class="n">MyList</span><span class="w"> </span><span class="o">*</span><span class="n">nums</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-82-73" name="__codelineno-82-73" href="#__codelineno-82-73"></a><span class="w"> </span><span class="n">assert</span><span class="p">(</span><span class="n">index</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">index</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">nums</span><span class="p">));</span>
|
||||
<a id="__codelineno-82-74" name="__codelineno-82-74" href="#__codelineno-82-74"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">num</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">nums</span><span class="o">-></span><span class="n">arr</span><span class="p">[</span><span class="n">index</span><span class="p">];</span>
|
||||
<a id="__codelineno-82-75" name="__codelineno-82-75" href="#__codelineno-82-75"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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">index</span><span class="p">;</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><span class="p">(</span><span class="n">nums</span><span class="p">)</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="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
|
|
|
@ -4304,77 +4304,82 @@
|
|||
<a id="__codelineno-10-17" name="__codelineno-10-17" href="#__codelineno-10-17"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">graph</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-18" name="__codelineno-10-18" href="#__codelineno-10-18"></a><span class="p">}</span>
|
||||
<a id="__codelineno-10-19" name="__codelineno-10-19" href="#__codelineno-10-19"></a>
|
||||
<a id="__codelineno-10-20" name="__codelineno-10-20" href="#__codelineno-10-20"></a><span class="cm">/* 添加顶点 */</span>
|
||||
<a id="__codelineno-10-21" name="__codelineno-10-21" href="#__codelineno-10-21"></a><span class="kt">void</span><span class="w"> </span><span class="nf">addVertex</span><span class="p">(</span><span class="n">GraphAdjMat</span><span class="w"> </span><span class="o">*</span><span class="n">graph</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">val</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-22" name="__codelineno-10-22" href="#__codelineno-10-22"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">MAX_SIZE</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-23" name="__codelineno-10-23" href="#__codelineno-10-23"></a><span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"图的顶点数量已达最大值</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-24" name="__codelineno-10-24" href="#__codelineno-10-24"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-25" name="__codelineno-10-25" href="#__codelineno-10-25"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-26" name="__codelineno-10-26" href="#__codelineno-10-26"></a><span class="w"> </span><span class="c1">// 添加第 n 个顶点,并将第 n 行和列置零</span>
|
||||
<a id="__codelineno-10-27" name="__codelineno-10-27" href="#__codelineno-10-27"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-28" name="__codelineno-10-28" href="#__codelineno-10-28"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">vertices</span><span class="p">[</span><span class="n">n</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">val</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-29" name="__codelineno-10-29" href="#__codelineno-10-29"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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="p">;</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">n</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-30" name="__codelineno-10-30" href="#__codelineno-10-30"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">n</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-31" name="__codelineno-10-31" href="#__codelineno-10-31"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-32" name="__codelineno-10-32" href="#__codelineno-10-32"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-33" name="__codelineno-10-33" href="#__codelineno-10-33"></a><span class="p">}</span>
|
||||
<a id="__codelineno-10-34" name="__codelineno-10-34" href="#__codelineno-10-34"></a>
|
||||
<a id="__codelineno-10-35" name="__codelineno-10-35" href="#__codelineno-10-35"></a><span class="cm">/* 删除顶点 */</span>
|
||||
<a id="__codelineno-10-36" name="__codelineno-10-36" href="#__codelineno-10-36"></a><span class="kt">void</span><span class="w"> </span><span class="nf">removeVertex</span><span class="p">(</span><span class="n">GraphAdjMat</span><span class="w"> </span><span class="o">*</span><span class="n">graph</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-37" name="__codelineno-10-37" href="#__codelineno-10-37"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">index</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">index</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-38" name="__codelineno-10-38" href="#__codelineno-10-38"></a><span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"顶点索引越界</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-39" name="__codelineno-10-39" href="#__codelineno-10-39"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-40" name="__codelineno-10-40" href="#__codelineno-10-40"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-41" name="__codelineno-10-41" href="#__codelineno-10-41"></a><span class="w"> </span><span class="c1">// 在顶点列表中移除索引 index 的顶点</span>
|
||||
<a id="__codelineno-10-42" name="__codelineno-10-42" href="#__codelineno-10-42"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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">index</span><span class="p">;</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">graph</span><span class="o">-></span><span class="n">size</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="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-43" name="__codelineno-10-43" href="#__codelineno-10-43"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">vertices</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">vertices</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>
|
||||
<a id="__codelineno-10-44" name="__codelineno-10-44" href="#__codelineno-10-44"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-45" name="__codelineno-10-45" href="#__codelineno-10-45"></a><span class="w"> </span><span class="c1">// 在邻接矩阵中删除索引 index 的行</span>
|
||||
<a id="__codelineno-10-46" name="__codelineno-10-46" href="#__codelineno-10-46"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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">index</span><span class="p">;</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">graph</span><span class="o">-></span><span class="n">size</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="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-47" name="__codelineno-10-47" href="#__codelineno-10-47"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="p">;</span><span class="w"> </span><span class="n">j</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-48" name="__codelineno-10-48" href="#__codelineno-10-48"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</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="n">j</span><span class="p">];</span>
|
||||
<a id="__codelineno-10-20" name="__codelineno-10-20" href="#__codelineno-10-20"></a><span class="cm">/* 析构函数 */</span>
|
||||
<a id="__codelineno-10-21" name="__codelineno-10-21" href="#__codelineno-10-21"></a><span class="kt">void</span><span class="w"> </span><span class="nf">delGraphAdjMat</span><span class="p">(</span><span class="n">GraphAdjMat</span><span class="w"> </span><span class="o">*</span><span class="n">graph</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-22" name="__codelineno-10-22" href="#__codelineno-10-22"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">graph</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-23" name="__codelineno-10-23" href="#__codelineno-10-23"></a><span class="p">}</span>
|
||||
<a id="__codelineno-10-24" name="__codelineno-10-24" href="#__codelineno-10-24"></a>
|
||||
<a id="__codelineno-10-25" name="__codelineno-10-25" href="#__codelineno-10-25"></a><span class="cm">/* 添加顶点 */</span>
|
||||
<a id="__codelineno-10-26" name="__codelineno-10-26" href="#__codelineno-10-26"></a><span class="kt">void</span><span class="w"> </span><span class="nf">addVertex</span><span class="p">(</span><span class="n">GraphAdjMat</span><span class="w"> </span><span class="o">*</span><span class="n">graph</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">val</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-27" name="__codelineno-10-27" href="#__codelineno-10-27"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">MAX_SIZE</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-28" name="__codelineno-10-28" href="#__codelineno-10-28"></a><span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"图的顶点数量已达最大值</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-29" name="__codelineno-10-29" href="#__codelineno-10-29"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-30" name="__codelineno-10-30" href="#__codelineno-10-30"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-31" name="__codelineno-10-31" href="#__codelineno-10-31"></a><span class="w"> </span><span class="c1">// 添加第 n 个顶点,并将第 n 行和列置零</span>
|
||||
<a id="__codelineno-10-32" name="__codelineno-10-32" href="#__codelineno-10-32"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-33" name="__codelineno-10-33" href="#__codelineno-10-33"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">vertices</span><span class="p">[</span><span class="n">n</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">val</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-34" name="__codelineno-10-34" href="#__codelineno-10-34"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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="p">;</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">n</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-35" name="__codelineno-10-35" href="#__codelineno-10-35"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">n</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-36" name="__codelineno-10-36" href="#__codelineno-10-36"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-37" name="__codelineno-10-37" href="#__codelineno-10-37"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-38" name="__codelineno-10-38" href="#__codelineno-10-38"></a><span class="p">}</span>
|
||||
<a id="__codelineno-10-39" name="__codelineno-10-39" href="#__codelineno-10-39"></a>
|
||||
<a id="__codelineno-10-40" name="__codelineno-10-40" href="#__codelineno-10-40"></a><span class="cm">/* 删除顶点 */</span>
|
||||
<a id="__codelineno-10-41" name="__codelineno-10-41" href="#__codelineno-10-41"></a><span class="kt">void</span><span class="w"> </span><span class="nf">removeVertex</span><span class="p">(</span><span class="n">GraphAdjMat</span><span class="w"> </span><span class="o">*</span><span class="n">graph</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-42" name="__codelineno-10-42" href="#__codelineno-10-42"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">index</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">index</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-43" name="__codelineno-10-43" href="#__codelineno-10-43"></a><span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"顶点索引越界</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-44" name="__codelineno-10-44" href="#__codelineno-10-44"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-45" name="__codelineno-10-45" href="#__codelineno-10-45"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-46" name="__codelineno-10-46" href="#__codelineno-10-46"></a><span class="w"> </span><span class="c1">// 在顶点列表中移除索引 index 的顶点</span>
|
||||
<a id="__codelineno-10-47" name="__codelineno-10-47" href="#__codelineno-10-47"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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">index</span><span class="p">;</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">graph</span><span class="o">-></span><span class="n">size</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="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-48" name="__codelineno-10-48" href="#__codelineno-10-48"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">vertices</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">vertices</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>
|
||||
<a id="__codelineno-10-49" name="__codelineno-10-49" href="#__codelineno-10-49"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-50" name="__codelineno-10-50" href="#__codelineno-10-50"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-51" name="__codelineno-10-51" href="#__codelineno-10-51"></a><span class="w"> </span><span class="c1">// 在邻接矩阵中删除索引 index 的列</span>
|
||||
<a id="__codelineno-10-52" name="__codelineno-10-52" href="#__codelineno-10-52"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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="p">;</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">graph</span><span class="o">-></span><span class="n">size</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-53" name="__codelineno-10-53" href="#__codelineno-10-53"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">index</span><span class="p">;</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</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="n">j</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-54" name="__codelineno-10-54" href="#__codelineno-10-54"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">];</span>
|
||||
<a id="__codelineno-10-50" name="__codelineno-10-50" href="#__codelineno-10-50"></a><span class="w"> </span><span class="c1">// 在邻接矩阵中删除索引 index 的行</span>
|
||||
<a id="__codelineno-10-51" name="__codelineno-10-51" href="#__codelineno-10-51"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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">index</span><span class="p">;</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">graph</span><span class="o">-></span><span class="n">size</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="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-52" name="__codelineno-10-52" href="#__codelineno-10-52"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="p">;</span><span class="w"> </span><span class="n">j</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-53" name="__codelineno-10-53" href="#__codelineno-10-53"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</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="n">j</span><span class="p">];</span>
|
||||
<a id="__codelineno-10-54" name="__codelineno-10-54" href="#__codelineno-10-54"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-55" name="__codelineno-10-55" href="#__codelineno-10-55"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-56" name="__codelineno-10-56" href="#__codelineno-10-56"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-57" name="__codelineno-10-57" href="#__codelineno-10-57"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="o">--</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-58" name="__codelineno-10-58" href="#__codelineno-10-58"></a><span class="p">}</span>
|
||||
<a id="__codelineno-10-59" name="__codelineno-10-59" href="#__codelineno-10-59"></a>
|
||||
<a id="__codelineno-10-60" name="__codelineno-10-60" href="#__codelineno-10-60"></a><span class="cm">/* 添加边 */</span>
|
||||
<a id="__codelineno-10-61" name="__codelineno-10-61" href="#__codelineno-10-61"></a><span class="c1">// 参数 i, j 对应 vertices 元素索引</span>
|
||||
<a id="__codelineno-10-62" name="__codelineno-10-62" href="#__codelineno-10-62"></a><span class="kt">void</span><span class="w"> </span><span class="nf">addEdge</span><span class="p">(</span><span class="n">GraphAdjMat</span><span class="w"> </span><span class="o">*</span><span class="n">graph</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">j</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-63" name="__codelineno-10-63" href="#__codelineno-10-63"></a><span class="w"> </span><span class="k">if</span><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">0</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">j</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">graph</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</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">j</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-64" name="__codelineno-10-64" href="#__codelineno-10-64"></a><span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"边索引越界或相等</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-65" name="__codelineno-10-65" href="#__codelineno-10-65"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-66" name="__codelineno-10-66" href="#__codelineno-10-66"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-67" name="__codelineno-10-67" href="#__codelineno-10-67"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-68" name="__codelineno-10-68" href="#__codelineno-10-68"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-69" name="__codelineno-10-69" href="#__codelineno-10-69"></a><span class="p">}</span>
|
||||
<a id="__codelineno-10-70" name="__codelineno-10-70" href="#__codelineno-10-70"></a>
|
||||
<a id="__codelineno-10-71" name="__codelineno-10-71" href="#__codelineno-10-71"></a><span class="cm">/* 删除边 */</span>
|
||||
<a id="__codelineno-10-72" name="__codelineno-10-72" href="#__codelineno-10-72"></a><span class="c1">// 参数 i, j 对应 vertices 元素索引</span>
|
||||
<a id="__codelineno-10-73" name="__codelineno-10-73" href="#__codelineno-10-73"></a><span class="kt">void</span><span class="w"> </span><span class="nf">removeEdge</span><span class="p">(</span><span class="n">GraphAdjMat</span><span class="w"> </span><span class="o">*</span><span class="n">graph</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">j</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-74" name="__codelineno-10-74" href="#__codelineno-10-74"></a><span class="w"> </span><span class="k">if</span><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">0</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">j</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">graph</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</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">j</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-75" name="__codelineno-10-75" href="#__codelineno-10-75"></a><span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"边索引越界或相等</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-76" name="__codelineno-10-76" href="#__codelineno-10-76"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-77" name="__codelineno-10-77" href="#__codelineno-10-77"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-78" name="__codelineno-10-78" href="#__codelineno-10-78"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-79" name="__codelineno-10-79" href="#__codelineno-10-79"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-80" name="__codelineno-10-80" href="#__codelineno-10-80"></a><span class="p">}</span>
|
||||
<a id="__codelineno-10-81" name="__codelineno-10-81" href="#__codelineno-10-81"></a>
|
||||
<a id="__codelineno-10-82" name="__codelineno-10-82" href="#__codelineno-10-82"></a><span class="cm">/* 打印邻接矩阵 */</span>
|
||||
<a id="__codelineno-10-83" name="__codelineno-10-83" href="#__codelineno-10-83"></a><span class="kt">void</span><span class="w"> </span><span class="nf">printGraphAdjMat</span><span class="p">(</span><span class="n">GraphAdjMat</span><span class="w"> </span><span class="o">*</span><span class="n">graph</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-84" name="__codelineno-10-84" href="#__codelineno-10-84"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"顶点列表 = "</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-85" name="__codelineno-10-85" href="#__codelineno-10-85"></a><span class="w"> </span><span class="n">printArray</span><span class="p">(</span><span class="n">graph</span><span class="o">-></span><span class="n">vertices</span><span class="p">,</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-86" name="__codelineno-10-86" href="#__codelineno-10-86"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"邻接矩阵 =</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-87" name="__codelineno-10-87" href="#__codelineno-10-87"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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="p">;</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">graph</span><span class="o">-></span><span class="n">size</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-88" name="__codelineno-10-88" href="#__codelineno-10-88"></a><span class="w"> </span><span class="n">printArray</span><span class="p">(</span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-89" name="__codelineno-10-89" href="#__codelineno-10-89"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-90" name="__codelineno-10-90" href="#__codelineno-10-90"></a><span class="p">}</span>
|
||||
<a id="__codelineno-10-56" name="__codelineno-10-56" href="#__codelineno-10-56"></a><span class="w"> </span><span class="c1">// 在邻接矩阵中删除索引 index 的列</span>
|
||||
<a id="__codelineno-10-57" name="__codelineno-10-57" href="#__codelineno-10-57"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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="p">;</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">graph</span><span class="o">-></span><span class="n">size</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-58" name="__codelineno-10-58" href="#__codelineno-10-58"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">index</span><span class="p">;</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</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="n">j</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-59" name="__codelineno-10-59" href="#__codelineno-10-59"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">];</span>
|
||||
<a id="__codelineno-10-60" name="__codelineno-10-60" href="#__codelineno-10-60"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-61" name="__codelineno-10-61" href="#__codelineno-10-61"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-62" name="__codelineno-10-62" href="#__codelineno-10-62"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="o">--</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-63" name="__codelineno-10-63" href="#__codelineno-10-63"></a><span class="p">}</span>
|
||||
<a id="__codelineno-10-64" name="__codelineno-10-64" href="#__codelineno-10-64"></a>
|
||||
<a id="__codelineno-10-65" name="__codelineno-10-65" href="#__codelineno-10-65"></a><span class="cm">/* 添加边 */</span>
|
||||
<a id="__codelineno-10-66" name="__codelineno-10-66" href="#__codelineno-10-66"></a><span class="c1">// 参数 i, j 对应 vertices 元素索引</span>
|
||||
<a id="__codelineno-10-67" name="__codelineno-10-67" href="#__codelineno-10-67"></a><span class="kt">void</span><span class="w"> </span><span class="nf">addEdge</span><span class="p">(</span><span class="n">GraphAdjMat</span><span class="w"> </span><span class="o">*</span><span class="n">graph</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">j</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-68" name="__codelineno-10-68" href="#__codelineno-10-68"></a><span class="w"> </span><span class="k">if</span><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">0</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">j</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">graph</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</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">j</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-69" name="__codelineno-10-69" href="#__codelineno-10-69"></a><span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"边索引越界或相等</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-70" name="__codelineno-10-70" href="#__codelineno-10-70"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-71" name="__codelineno-10-71" href="#__codelineno-10-71"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-72" name="__codelineno-10-72" href="#__codelineno-10-72"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-73" name="__codelineno-10-73" href="#__codelineno-10-73"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-74" name="__codelineno-10-74" href="#__codelineno-10-74"></a><span class="p">}</span>
|
||||
<a id="__codelineno-10-75" name="__codelineno-10-75" href="#__codelineno-10-75"></a>
|
||||
<a id="__codelineno-10-76" name="__codelineno-10-76" href="#__codelineno-10-76"></a><span class="cm">/* 删除边 */</span>
|
||||
<a id="__codelineno-10-77" name="__codelineno-10-77" href="#__codelineno-10-77"></a><span class="c1">// 参数 i, j 对应 vertices 元素索引</span>
|
||||
<a id="__codelineno-10-78" name="__codelineno-10-78" href="#__codelineno-10-78"></a><span class="kt">void</span><span class="w"> </span><span class="nf">removeEdge</span><span class="p">(</span><span class="n">GraphAdjMat</span><span class="w"> </span><span class="o">*</span><span class="n">graph</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">j</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-79" name="__codelineno-10-79" href="#__codelineno-10-79"></a><span class="w"> </span><span class="k">if</span><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">0</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">j</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">graph</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">j</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</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">j</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-80" name="__codelineno-10-80" href="#__codelineno-10-80"></a><span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"边索引越界或相等</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-81" name="__codelineno-10-81" href="#__codelineno-10-81"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-82" name="__codelineno-10-82" href="#__codelineno-10-82"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-83" name="__codelineno-10-83" href="#__codelineno-10-83"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-84" name="__codelineno-10-84" href="#__codelineno-10-84"></a><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-85" name="__codelineno-10-85" href="#__codelineno-10-85"></a><span class="p">}</span>
|
||||
<a id="__codelineno-10-86" name="__codelineno-10-86" href="#__codelineno-10-86"></a>
|
||||
<a id="__codelineno-10-87" name="__codelineno-10-87" href="#__codelineno-10-87"></a><span class="cm">/* 打印邻接矩阵 */</span>
|
||||
<a id="__codelineno-10-88" name="__codelineno-10-88" href="#__codelineno-10-88"></a><span class="kt">void</span><span class="w"> </span><span class="nf">printGraphAdjMat</span><span class="p">(</span><span class="n">GraphAdjMat</span><span class="w"> </span><span class="o">*</span><span class="n">graph</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-89" name="__codelineno-10-89" href="#__codelineno-10-89"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"顶点列表 = "</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-90" name="__codelineno-10-90" href="#__codelineno-10-90"></a><span class="w"> </span><span class="n">printArray</span><span class="p">(</span><span class="n">graph</span><span class="o">-></span><span class="n">vertices</span><span class="p">,</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-91" name="__codelineno-10-91" href="#__codelineno-10-91"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"邻接矩阵 =</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-92" name="__codelineno-10-92" href="#__codelineno-10-92"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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="p">;</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">graph</span><span class="o">-></span><span class="n">size</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-93" name="__codelineno-10-93" href="#__codelineno-10-93"></a><span class="w"> </span><span class="n">printArray</span><span class="p">(</span><span class="n">graph</span><span class="o">-></span><span class="n">adjMat</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="w"> </span><span class="n">graph</span><span class="o">-></span><span class="n">size</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-94" name="__codelineno-10-94" href="#__codelineno-10-94"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-95" name="__codelineno-10-95" href="#__codelineno-10-95"></a><span class="p">}</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
|
@ -4556,7 +4556,7 @@
|
|||
<a id="__codelineno-10-14" name="__codelineno-10-14" href="#__codelineno-10-14"></a><span class="p">}</span><span class="w"> </span><span class="n">HashMapChaining</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-15" name="__codelineno-10-15" href="#__codelineno-10-15"></a>
|
||||
<a id="__codelineno-10-16" name="__codelineno-10-16" href="#__codelineno-10-16"></a><span class="cm">/* 构造函数 */</span>
|
||||
<a id="__codelineno-10-17" name="__codelineno-10-17" href="#__codelineno-10-17"></a><span class="n">HashMapChaining</span><span class="w"> </span><span class="o">*</span><span class="nf">initHashMapChaining</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-17" name="__codelineno-10-17" href="#__codelineno-10-17"></a><span class="n">HashMapChaining</span><span class="w"> </span><span class="o">*</span><span class="nf">newHashMapChaining</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-18" name="__codelineno-10-18" href="#__codelineno-10-18"></a><span class="w"> </span><span class="n">HashMapChaining</span><span class="w"> </span><span class="o">*</span><span class="n">hashMap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">HashMapChaining</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="n">HashMapChaining</span><span class="p">));</span>
|
||||
<a id="__codelineno-10-19" name="__codelineno-10-19" href="#__codelineno-10-19"></a><span class="w"> </span><span class="n">hashMap</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-20" name="__codelineno-10-20" href="#__codelineno-10-20"></a><span class="w"> </span><span class="n">hashMap</span><span class="o">-></span><span class="n">capacity</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span>
|
||||
|
@ -4570,14 +4570,14 @@
|
|||
<a id="__codelineno-10-28" name="__codelineno-10-28" href="#__codelineno-10-28"></a><span class="p">}</span>
|
||||
<a id="__codelineno-10-29" name="__codelineno-10-29" href="#__codelineno-10-29"></a>
|
||||
<a id="__codelineno-10-30" name="__codelineno-10-30" href="#__codelineno-10-30"></a><span class="cm">/* 析构函数 */</span>
|
||||
<a id="__codelineno-10-31" name="__codelineno-10-31" href="#__codelineno-10-31"></a><span class="kt">void</span><span class="w"> </span><span class="nf">freeHashMapChaining</span><span class="p">(</span><span class="n">HashMapChaining</span><span class="w"> </span><span class="o">*</span><span class="n">hashMap</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-31" name="__codelineno-10-31" href="#__codelineno-10-31"></a><span class="kt">void</span><span class="w"> </span><span class="nf">delHashMapChaining</span><span class="p">(</span><span class="n">HashMapChaining</span><span class="w"> </span><span class="o">*</span><span class="n">hashMap</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-32" name="__codelineno-10-32" href="#__codelineno-10-32"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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="p">;</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">hashMap</span><span class="o">-></span><span class="n">capacity</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-33" name="__codelineno-10-33" href="#__codelineno-10-33"></a><span class="w"> </span><span class="n">Node</span><span class="w"> </span><span class="o">*</span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">hashMap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
|
||||
<a id="__codelineno-10-34" name="__codelineno-10-34" href="#__codelineno-10-34"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="n">cur</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-35" name="__codelineno-10-35" href="#__codelineno-10-35"></a><span class="w"> </span><span class="n">Node</span><span class="w"> </span><span class="o">*</span><span class="n">temp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cur</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-35" name="__codelineno-10-35" href="#__codelineno-10-35"></a><span class="w"> </span><span class="n">Node</span><span class="w"> </span><span class="o">*</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="p">;</span>
|
||||
<a id="__codelineno-10-36" name="__codelineno-10-36" href="#__codelineno-10-36"></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">next</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-37" name="__codelineno-10-37" href="#__codelineno-10-37"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">temp</span><span class="o">-></span><span class="n">pair</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-38" name="__codelineno-10-38" href="#__codelineno-10-38"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">temp</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-37" name="__codelineno-10-37" href="#__codelineno-10-37"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">tmp</span><span class="o">-></span><span class="n">pair</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-38" name="__codelineno-10-38" href="#__codelineno-10-38"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">tmp</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-39" name="__codelineno-10-39" href="#__codelineno-10-39"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-40" name="__codelineno-10-40" href="#__codelineno-10-40"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-41" name="__codelineno-10-41" href="#__codelineno-10-41"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">hashMap</span><span class="o">-></span><span class="n">buckets</span><span class="p">);</span>
|
||||
|
@ -4664,7 +4664,7 @@
|
|||
<a id="__codelineno-10-122" name="__codelineno-10-122" href="#__codelineno-10-122"></a><span class="p">}</span>
|
||||
<a id="__codelineno-10-123" name="__codelineno-10-123" href="#__codelineno-10-123"></a>
|
||||
<a id="__codelineno-10-124" name="__codelineno-10-124" href="#__codelineno-10-124"></a><span class="cm">/* 删除操作 */</span>
|
||||
<a id="__codelineno-10-125" name="__codelineno-10-125" href="#__codelineno-10-125"></a><span class="kt">void</span><span class="w"> </span><span class="nf">removeKey</span><span class="p">(</span><span class="n">HashMapChaining</span><span class="w"> </span><span class="o">*</span><span class="n">hashMap</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">key</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-125" name="__codelineno-10-125" href="#__codelineno-10-125"></a><span class="kt">void</span><span class="w"> </span><span class="nf">removeItem</span><span class="p">(</span><span class="n">HashMapChaining</span><span class="w"> </span><span class="o">*</span><span class="n">hashMap</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">key</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-126" name="__codelineno-10-126" href="#__codelineno-10-126"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">hashFunc</span><span class="p">(</span><span class="n">hashMap</span><span class="p">,</span><span class="w"> </span><span class="n">key</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-127" name="__codelineno-10-127" href="#__codelineno-10-127"></a><span class="w"> </span><span class="n">Node</span><span class="w"> </span><span class="o">*</span><span class="n">cur</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">hashMap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">];</span>
|
||||
<a id="__codelineno-10-128" name="__codelineno-10-128" href="#__codelineno-10-128"></a><span class="w"> </span><span class="n">Node</span><span class="w"> </span><span class="o">*</span><span class="n">pre</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span>
|
||||
|
|
|
@ -4716,122 +4716,124 @@
|
|||
<a id="__codelineno-35-6" name="__codelineno-35-6" href="#__codelineno-35-6"></a>
|
||||
<a id="__codelineno-35-7" name="__codelineno-35-7" href="#__codelineno-35-7"></a><span class="cm">/* 基于数组简易实现的哈希表 */</span>
|
||||
<a id="__codelineno-35-8" name="__codelineno-35-8" href="#__codelineno-35-8"></a><span class="k">typedef</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-9" name="__codelineno-35-9" href="#__codelineno-35-9"></a><span class="w"> </span><span class="n">Pair</span><span class="w"> </span><span class="o">*</span><span class="n">buckets</span><span class="p">[</span><span class="n">HASH_MAP_DEFAULT_SIZE</span><span class="p">];</span>
|
||||
<a id="__codelineno-35-9" name="__codelineno-35-9" href="#__codelineno-35-9"></a><span class="w"> </span><span class="n">Pair</span><span class="w"> </span><span class="o">*</span><span class="n">buckets</span><span class="p">[</span><span class="n">HASHTABLE_CAPACITY</span><span class="p">];</span>
|
||||
<a id="__codelineno-35-10" name="__codelineno-35-10" href="#__codelineno-35-10"></a><span class="p">}</span><span class="w"> </span><span class="n">ArrayHashMap</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-11" name="__codelineno-35-11" href="#__codelineno-35-11"></a>
|
||||
<a id="__codelineno-35-12" name="__codelineno-35-12" href="#__codelineno-35-12"></a><span class="cm">/* 哈希表初始化函数 */</span>
|
||||
<a id="__codelineno-35-12" name="__codelineno-35-12" href="#__codelineno-35-12"></a><span class="cm">/* 构造函数 */</span>
|
||||
<a id="__codelineno-35-13" name="__codelineno-35-13" href="#__codelineno-35-13"></a><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="nf">newArrayHashMap</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-14" name="__codelineno-35-14" href="#__codelineno-35-14"></a><span class="w"> </span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">map</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="p">));</span>
|
||||
<a id="__codelineno-35-15" name="__codelineno-35-15" href="#__codelineno-35-15"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">map</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-14" name="__codelineno-35-14" href="#__codelineno-35-14"></a><span class="w"> </span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">hmap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="p">));</span>
|
||||
<a id="__codelineno-35-15" name="__codelineno-35-15" href="#__codelineno-35-15"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">hmap</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-16" name="__codelineno-35-16" href="#__codelineno-35-16"></a><span class="p">}</span>
|
||||
<a id="__codelineno-35-17" name="__codelineno-35-17" href="#__codelineno-35-17"></a>
|
||||
<a id="__codelineno-35-18" name="__codelineno-35-18" href="#__codelineno-35-18"></a><span class="cm">/* 添加操作 */</span>
|
||||
<a id="__codelineno-35-19" name="__codelineno-35-19" href="#__codelineno-35-19"></a><span class="kt">void</span><span class="w"> </span><span class="nf">put</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">d</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">key</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">val</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-20" name="__codelineno-35-20" href="#__codelineno-35-20"></a><span class="w"> </span><span class="n">Pair</span><span class="w"> </span><span class="o">*</span><span class="n">Pair</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="n">Pair</span><span class="p">));</span>
|
||||
<a id="__codelineno-35-21" name="__codelineno-35-21" href="#__codelineno-35-21"></a><span class="w"> </span><span class="n">Pair</span><span class="o">-></span><span class="n">key</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">key</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-22" name="__codelineno-35-22" href="#__codelineno-35-22"></a><span class="w"> </span><span class="n">Pair</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">malloc</span><span class="p">(</span><span class="n">strlen</span><span class="p">(</span><span class="n">val</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-23" name="__codelineno-35-23" href="#__codelineno-35-23"></a><span class="w"> </span><span class="n">strcpy</span><span class="p">(</span><span class="n">Pair</span><span class="o">-></span><span class="n">val</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-24" name="__codelineno-35-24" href="#__codelineno-35-24"></a>
|
||||
<a id="__codelineno-35-25" name="__codelineno-35-25" href="#__codelineno-35-25"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">hashFunc</span><span class="p">(</span><span class="n">key</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-26" name="__codelineno-35-26" href="#__codelineno-35-26"></a><span class="w"> </span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Pair</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-18" name="__codelineno-35-18" href="#__codelineno-35-18"></a><span class="cm">/* 析构函数 */</span>
|
||||
<a id="__codelineno-35-19" name="__codelineno-35-19" href="#__codelineno-35-19"></a><span class="kt">void</span><span class="w"> </span><span class="nf">delArrayHashMap</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">hmap</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-20" name="__codelineno-35-20" href="#__codelineno-35-20"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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="p">;</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">HASHTABLE_CAPACITY</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-21" name="__codelineno-35-21" href="#__codelineno-35-21"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-22" name="__codelineno-35-22" href="#__codelineno-35-22"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">val</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-23" name="__codelineno-35-23" href="#__codelineno-35-23"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
|
||||
<a id="__codelineno-35-24" name="__codelineno-35-24" href="#__codelineno-35-24"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-25" name="__codelineno-35-25" href="#__codelineno-35-25"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-26" name="__codelineno-35-26" href="#__codelineno-35-26"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">hmap</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-27" name="__codelineno-35-27" href="#__codelineno-35-27"></a><span class="p">}</span>
|
||||
<a id="__codelineno-35-28" name="__codelineno-35-28" href="#__codelineno-35-28"></a>
|
||||
<a id="__codelineno-35-29" name="__codelineno-35-29" href="#__codelineno-35-29"></a><span class="cm">/* 删除操作 */</span>
|
||||
<a id="__codelineno-35-30" name="__codelineno-35-30" href="#__codelineno-35-30"></a><span class="kt">void</span><span class="w"> </span><span class="nf">removeItem</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">d</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">key</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-31" name="__codelineno-35-31" href="#__codelineno-35-31"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">hashFunc</span><span class="p">(</span><span class="n">key</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-32" name="__codelineno-35-32" href="#__codelineno-35-32"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="o">-></span><span class="n">val</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-33" name="__codelineno-35-33" href="#__codelineno-35-33"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]);</span>
|
||||
<a id="__codelineno-35-34" name="__codelineno-35-34" href="#__codelineno-35-34"></a><span class="w"> </span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-35" name="__codelineno-35-35" href="#__codelineno-35-35"></a><span class="p">}</span>
|
||||
<a id="__codelineno-35-36" name="__codelineno-35-36" href="#__codelineno-35-36"></a>
|
||||
<a id="__codelineno-35-37" name="__codelineno-35-37" href="#__codelineno-35-37"></a><span class="cm">/* 获取所有键值对 */</span>
|
||||
<a id="__codelineno-35-38" name="__codelineno-35-38" href="#__codelineno-35-38"></a><span class="kt">void</span><span class="w"> </span><span class="nf">pairSet</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">d</span><span class="p">,</span><span class="w"> </span><span class="n">MapSet</span><span class="w"> </span><span class="o">*</span><span class="n">set</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-39" name="__codelineno-35-39" href="#__codelineno-35-39"></a><span class="w"> </span><span class="n">Pair</span><span class="w"> </span><span class="o">*</span><span class="n">entries</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-40" name="__codelineno-35-40" href="#__codelineno-35-40"></a><span class="w"> </span><span class="kt">int</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="p">,</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-41" name="__codelineno-35-41" href="#__codelineno-35-41"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">total</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-42" name="__codelineno-35-42" href="#__codelineno-35-42"></a>
|
||||
<a id="__codelineno-35-43" name="__codelineno-35-43" href="#__codelineno-35-43"></a><span class="w"> </span><span class="cm">/* 统计有效键值对数量 */</span>
|
||||
<a id="__codelineno-35-44" name="__codelineno-35-44" href="#__codelineno-35-44"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">HASH_MAP_DEFAULT_SIZE</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-45" name="__codelineno-35-45" href="#__codelineno-35-45"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-46" name="__codelineno-35-46" href="#__codelineno-35-46"></a><span class="w"> </span><span class="n">total</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-47" name="__codelineno-35-47" href="#__codelineno-35-47"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-48" name="__codelineno-35-48" href="#__codelineno-35-48"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-49" name="__codelineno-35-49" href="#__codelineno-35-49"></a>
|
||||
<a id="__codelineno-35-50" name="__codelineno-35-50" href="#__codelineno-35-50"></a><span class="w"> </span><span class="n">entries</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="n">Pair</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">total</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-51" name="__codelineno-35-51" href="#__codelineno-35-51"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">HASH_MAP_DEFAULT_SIZE</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-52" name="__codelineno-35-52" href="#__codelineno-35-52"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-53" name="__codelineno-35-53" href="#__codelineno-35-53"></a><span class="w"> </span><span class="n">entries</span><span class="p">[</span><span class="n">index</span><span class="p">].</span><span class="n">key</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">key</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-54" name="__codelineno-35-54" href="#__codelineno-35-54"></a><span class="w"> </span><span class="n">entries</span><span class="p">[</span><span class="n">index</span><span class="p">].</span><span class="n">val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="n">strlen</span><span class="p">(</span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">val</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">));</span>
|
||||
<a id="__codelineno-35-55" name="__codelineno-35-55" href="#__codelineno-35-55"></a><span class="w"> </span><span class="n">strcpy</span><span class="p">(</span><span class="n">entries</span><span class="p">[</span><span class="n">index</span><span class="p">].</span><span class="n">val</span><span class="p">,</span><span class="w"> </span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">val</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-56" name="__codelineno-35-56" href="#__codelineno-35-56"></a><span class="w"> </span><span class="n">index</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-29" name="__codelineno-35-29" href="#__codelineno-35-29"></a><span class="cm">/* 添加操作 */</span>
|
||||
<a id="__codelineno-35-30" name="__codelineno-35-30" href="#__codelineno-35-30"></a><span class="kt">void</span><span class="w"> </span><span class="nf">put</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">hmap</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">key</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">val</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-31" name="__codelineno-35-31" href="#__codelineno-35-31"></a><span class="w"> </span><span class="n">Pair</span><span class="w"> </span><span class="o">*</span><span class="n">Pair</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="n">Pair</span><span class="p">));</span>
|
||||
<a id="__codelineno-35-32" name="__codelineno-35-32" href="#__codelineno-35-32"></a><span class="w"> </span><span class="n">Pair</span><span class="o">-></span><span class="n">key</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">key</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-33" name="__codelineno-35-33" href="#__codelineno-35-33"></a><span class="w"> </span><span class="n">Pair</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">malloc</span><span class="p">(</span><span class="n">strlen</span><span class="p">(</span><span class="n">val</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-34" name="__codelineno-35-34" href="#__codelineno-35-34"></a><span class="w"> </span><span class="n">strcpy</span><span class="p">(</span><span class="n">Pair</span><span class="o">-></span><span class="n">val</span><span class="p">,</span><span class="w"> </span><span class="n">val</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-35" name="__codelineno-35-35" href="#__codelineno-35-35"></a>
|
||||
<a id="__codelineno-35-36" name="__codelineno-35-36" href="#__codelineno-35-36"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">hashFunc</span><span class="p">(</span><span class="n">key</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-37" name="__codelineno-35-37" href="#__codelineno-35-37"></a><span class="w"> </span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Pair</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-38" name="__codelineno-35-38" href="#__codelineno-35-38"></a><span class="p">}</span>
|
||||
<a id="__codelineno-35-39" name="__codelineno-35-39" href="#__codelineno-35-39"></a>
|
||||
<a id="__codelineno-35-40" name="__codelineno-35-40" href="#__codelineno-35-40"></a><span class="cm">/* 删除操作 */</span>
|
||||
<a id="__codelineno-35-41" name="__codelineno-35-41" href="#__codelineno-35-41"></a><span class="kt">void</span><span class="w"> </span><span class="nf">removeItem</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">hmap</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">key</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-42" name="__codelineno-35-42" href="#__codelineno-35-42"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">hashFunc</span><span class="p">(</span><span class="n">key</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-43" name="__codelineno-35-43" href="#__codelineno-35-43"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="o">-></span><span class="n">val</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-44" name="__codelineno-35-44" href="#__codelineno-35-44"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]);</span>
|
||||
<a id="__codelineno-35-45" name="__codelineno-35-45" href="#__codelineno-35-45"></a><span class="w"> </span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-46" name="__codelineno-35-46" href="#__codelineno-35-46"></a><span class="p">}</span>
|
||||
<a id="__codelineno-35-47" name="__codelineno-35-47" href="#__codelineno-35-47"></a>
|
||||
<a id="__codelineno-35-48" name="__codelineno-35-48" href="#__codelineno-35-48"></a><span class="cm">/* 获取所有键值对 */</span>
|
||||
<a id="__codelineno-35-49" name="__codelineno-35-49" href="#__codelineno-35-49"></a><span class="kt">void</span><span class="w"> </span><span class="nf">pairSet</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">hmap</span><span class="p">,</span><span class="w"> </span><span class="n">MapSet</span><span class="w"> </span><span class="o">*</span><span class="n">set</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-50" name="__codelineno-35-50" href="#__codelineno-35-50"></a><span class="w"> </span><span class="n">Pair</span><span class="w"> </span><span class="o">*</span><span class="n">entries</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-51" name="__codelineno-35-51" href="#__codelineno-35-51"></a><span class="w"> </span><span class="kt">int</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="p">,</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-52" name="__codelineno-35-52" href="#__codelineno-35-52"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">total</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-53" name="__codelineno-35-53" href="#__codelineno-35-53"></a><span class="w"> </span><span class="cm">/* 统计有效键值对数量 */</span>
|
||||
<a id="__codelineno-35-54" name="__codelineno-35-54" href="#__codelineno-35-54"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">HASHTABLE_CAPACITY</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-55" name="__codelineno-35-55" href="#__codelineno-35-55"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-56" name="__codelineno-35-56" href="#__codelineno-35-56"></a><span class="w"> </span><span class="n">total</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-57" name="__codelineno-35-57" href="#__codelineno-35-57"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-58" name="__codelineno-35-58" href="#__codelineno-35-58"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-59" name="__codelineno-35-59" href="#__codelineno-35-59"></a>
|
||||
<a id="__codelineno-35-60" name="__codelineno-35-60" href="#__codelineno-35-60"></a><span class="w"> </span><span class="n">set</span><span class="o">-></span><span class="n">set</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">entries</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-61" name="__codelineno-35-61" href="#__codelineno-35-61"></a><span class="w"> </span><span class="n">set</span><span class="o">-></span><span class="n">len</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">total</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-62" name="__codelineno-35-62" href="#__codelineno-35-62"></a><span class="p">}</span>
|
||||
<a id="__codelineno-35-63" name="__codelineno-35-63" href="#__codelineno-35-63"></a>
|
||||
<a id="__codelineno-35-64" name="__codelineno-35-64" href="#__codelineno-35-64"></a><span class="cm">/* 获取所有键 */</span>
|
||||
<a id="__codelineno-35-65" name="__codelineno-35-65" href="#__codelineno-35-65"></a><span class="kt">void</span><span class="w"> </span><span class="nf">keySet</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">d</span><span class="p">,</span><span class="w"> </span><span class="n">MapSet</span><span class="w"> </span><span class="o">*</span><span class="n">set</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-66" name="__codelineno-35-66" href="#__codelineno-35-66"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">keys</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-67" name="__codelineno-35-67" href="#__codelineno-35-67"></a><span class="w"> </span><span class="kt">int</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="p">,</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-68" name="__codelineno-35-68" href="#__codelineno-35-68"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">total</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-69" name="__codelineno-35-69" href="#__codelineno-35-69"></a>
|
||||
<a id="__codelineno-35-70" name="__codelineno-35-70" href="#__codelineno-35-70"></a><span class="w"> </span><span class="cm">/* 统计有效键值对数量 */</span>
|
||||
<a id="__codelineno-35-71" name="__codelineno-35-71" href="#__codelineno-35-71"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">HASH_MAP_DEFAULT_SIZE</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-72" name="__codelineno-35-72" href="#__codelineno-35-72"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-73" name="__codelineno-35-73" href="#__codelineno-35-73"></a><span class="w"> </span><span class="n">total</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-74" name="__codelineno-35-74" href="#__codelineno-35-74"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-75" name="__codelineno-35-75" href="#__codelineno-35-75"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-76" name="__codelineno-35-76" href="#__codelineno-35-76"></a>
|
||||
<a id="__codelineno-35-77" name="__codelineno-35-77" href="#__codelineno-35-77"></a><span class="w"> </span><span class="n">keys</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="n">total</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">));</span>
|
||||
<a id="__codelineno-35-78" name="__codelineno-35-78" href="#__codelineno-35-78"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">HASH_MAP_DEFAULT_SIZE</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-79" name="__codelineno-35-79" href="#__codelineno-35-79"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-80" name="__codelineno-35-80" href="#__codelineno-35-80"></a><span class="w"> </span><span class="n">keys</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">key</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-81" name="__codelineno-35-81" href="#__codelineno-35-81"></a><span class="w"> </span><span class="n">index</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-59" name="__codelineno-35-59" href="#__codelineno-35-59"></a><span class="w"> </span><span class="n">entries</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="n">Pair</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">total</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-60" name="__codelineno-35-60" href="#__codelineno-35-60"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">HASHTABLE_CAPACITY</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-61" name="__codelineno-35-61" href="#__codelineno-35-61"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-62" name="__codelineno-35-62" href="#__codelineno-35-62"></a><span class="w"> </span><span class="n">entries</span><span class="p">[</span><span class="n">index</span><span class="p">].</span><span class="n">key</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">key</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-63" name="__codelineno-35-63" href="#__codelineno-35-63"></a><span class="w"> </span><span class="n">entries</span><span class="p">[</span><span class="n">index</span><span class="p">].</span><span class="n">val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="n">strlen</span><span class="p">(</span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">val</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">));</span>
|
||||
<a id="__codelineno-35-64" name="__codelineno-35-64" href="#__codelineno-35-64"></a><span class="w"> </span><span class="n">strcpy</span><span class="p">(</span><span class="n">entries</span><span class="p">[</span><span class="n">index</span><span class="p">].</span><span class="n">val</span><span class="p">,</span><span class="w"> </span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">val</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-65" name="__codelineno-35-65" href="#__codelineno-35-65"></a><span class="w"> </span><span class="n">index</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-66" name="__codelineno-35-66" href="#__codelineno-35-66"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-67" name="__codelineno-35-67" href="#__codelineno-35-67"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-68" name="__codelineno-35-68" href="#__codelineno-35-68"></a><span class="w"> </span><span class="n">set</span><span class="o">-></span><span class="n">set</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">entries</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-69" name="__codelineno-35-69" href="#__codelineno-35-69"></a><span class="w"> </span><span class="n">set</span><span class="o">-></span><span class="n">len</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">total</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-70" name="__codelineno-35-70" href="#__codelineno-35-70"></a><span class="p">}</span>
|
||||
<a id="__codelineno-35-71" name="__codelineno-35-71" href="#__codelineno-35-71"></a>
|
||||
<a id="__codelineno-35-72" name="__codelineno-35-72" href="#__codelineno-35-72"></a><span class="cm">/* 获取所有键 */</span>
|
||||
<a id="__codelineno-35-73" name="__codelineno-35-73" href="#__codelineno-35-73"></a><span class="kt">void</span><span class="w"> </span><span class="nf">keySet</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">hmap</span><span class="p">,</span><span class="w"> </span><span class="n">MapSet</span><span class="w"> </span><span class="o">*</span><span class="n">set</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-74" name="__codelineno-35-74" href="#__codelineno-35-74"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">keys</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-75" name="__codelineno-35-75" href="#__codelineno-35-75"></a><span class="w"> </span><span class="kt">int</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="p">,</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-76" name="__codelineno-35-76" href="#__codelineno-35-76"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">total</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-77" name="__codelineno-35-77" href="#__codelineno-35-77"></a><span class="w"> </span><span class="cm">/* 统计有效键值对数量 */</span>
|
||||
<a id="__codelineno-35-78" name="__codelineno-35-78" href="#__codelineno-35-78"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">HASHTABLE_CAPACITY</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-79" name="__codelineno-35-79" href="#__codelineno-35-79"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-80" name="__codelineno-35-80" href="#__codelineno-35-80"></a><span class="w"> </span><span class="n">total</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-81" name="__codelineno-35-81" href="#__codelineno-35-81"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-82" name="__codelineno-35-82" href="#__codelineno-35-82"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-83" name="__codelineno-35-83" href="#__codelineno-35-83"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-84" name="__codelineno-35-84" href="#__codelineno-35-84"></a>
|
||||
<a id="__codelineno-35-85" name="__codelineno-35-85" href="#__codelineno-35-85"></a><span class="w"> </span><span class="n">set</span><span class="o">-></span><span class="n">set</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">keys</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-86" name="__codelineno-35-86" href="#__codelineno-35-86"></a><span class="w"> </span><span class="n">set</span><span class="o">-></span><span class="n">len</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">total</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-87" name="__codelineno-35-87" href="#__codelineno-35-87"></a><span class="p">}</span>
|
||||
<a id="__codelineno-35-88" name="__codelineno-35-88" href="#__codelineno-35-88"></a>
|
||||
<a id="__codelineno-35-89" name="__codelineno-35-89" href="#__codelineno-35-89"></a><span class="cm">/* 获取所有值 */</span>
|
||||
<a id="__codelineno-35-90" name="__codelineno-35-90" href="#__codelineno-35-90"></a><span class="kt">void</span><span class="w"> </span><span class="nf">valueSet</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">d</span><span class="p">,</span><span class="w"> </span><span class="n">MapSet</span><span class="w"> </span><span class="o">*</span><span class="n">set</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-91" name="__codelineno-35-91" href="#__codelineno-35-91"></a><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">**</span><span class="n">vals</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-92" name="__codelineno-35-92" href="#__codelineno-35-92"></a><span class="w"> </span><span class="kt">int</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="p">,</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-93" name="__codelineno-35-93" href="#__codelineno-35-93"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">total</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-94" name="__codelineno-35-94" href="#__codelineno-35-94"></a>
|
||||
<a id="__codelineno-35-95" name="__codelineno-35-95" href="#__codelineno-35-95"></a><span class="w"> </span><span class="cm">/* 统计有效键值对数量 */</span>
|
||||
<a id="__codelineno-35-96" name="__codelineno-35-96" href="#__codelineno-35-96"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">HASH_MAP_DEFAULT_SIZE</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-97" name="__codelineno-35-97" href="#__codelineno-35-97"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-98" name="__codelineno-35-98" href="#__codelineno-35-98"></a><span class="w"> </span><span class="n">total</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-99" name="__codelineno-35-99" href="#__codelineno-35-99"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-100" name="__codelineno-35-100" href="#__codelineno-35-100"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-101" name="__codelineno-35-101" href="#__codelineno-35-101"></a>
|
||||
<a id="__codelineno-35-102" name="__codelineno-35-102" href="#__codelineno-35-102"></a><span class="w"> </span><span class="n">vals</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="n">total</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="p">));</span>
|
||||
<a id="__codelineno-35-103" name="__codelineno-35-103" href="#__codelineno-35-103"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">HASH_MAP_DEFAULT_SIZE</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-104" name="__codelineno-35-104" href="#__codelineno-35-104"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-105" name="__codelineno-35-105" href="#__codelineno-35-105"></a><span class="w"> </span><span class="n">vals</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">d</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">val</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-106" name="__codelineno-35-106" href="#__codelineno-35-106"></a><span class="w"> </span><span class="n">index</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-107" name="__codelineno-35-107" href="#__codelineno-35-107"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-108" name="__codelineno-35-108" href="#__codelineno-35-108"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-109" name="__codelineno-35-109" href="#__codelineno-35-109"></a>
|
||||
<a id="__codelineno-35-110" name="__codelineno-35-110" href="#__codelineno-35-110"></a><span class="w"> </span><span class="n">set</span><span class="o">-></span><span class="n">set</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">vals</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-111" name="__codelineno-35-111" href="#__codelineno-35-111"></a><span class="w"> </span><span class="n">set</span><span class="o">-></span><span class="n">len</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">total</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-112" name="__codelineno-35-112" href="#__codelineno-35-112"></a><span class="p">}</span>
|
||||
<a id="__codelineno-35-113" name="__codelineno-35-113" href="#__codelineno-35-113"></a>
|
||||
<a id="__codelineno-35-114" name="__codelineno-35-114" href="#__codelineno-35-114"></a><span class="cm">/* 打印哈希表 */</span>
|
||||
<a id="__codelineno-35-115" name="__codelineno-35-115" href="#__codelineno-35-115"></a><span class="kt">void</span><span class="w"> </span><span class="nf">print</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">d</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-116" name="__codelineno-35-116" href="#__codelineno-35-116"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-117" name="__codelineno-35-117" href="#__codelineno-35-117"></a><span class="w"> </span><span class="n">MapSet</span><span class="w"> </span><span class="n">set</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-118" name="__codelineno-35-118" href="#__codelineno-35-118"></a><span class="w"> </span><span class="n">pairSet</span><span class="p">(</span><span class="n">d</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">set</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-119" name="__codelineno-35-119" href="#__codelineno-35-119"></a><span class="w"> </span><span class="n">Pair</span><span class="w"> </span><span class="o">*</span><span class="n">entries</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">Pair</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">set</span><span class="p">.</span><span class="n">set</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-120" name="__codelineno-35-120" href="#__codelineno-35-120"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">set</span><span class="p">.</span><span class="n">len</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-121" name="__codelineno-35-121" href="#__codelineno-35-121"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"%d -> %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">entries</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">key</span><span class="p">,</span><span class="w"> </span><span class="n">entries</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">val</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-122" name="__codelineno-35-122" href="#__codelineno-35-122"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-123" name="__codelineno-35-123" href="#__codelineno-35-123"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">set</span><span class="p">.</span><span class="n">set</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-124" name="__codelineno-35-124" href="#__codelineno-35-124"></a><span class="p">}</span>
|
||||
<a id="__codelineno-35-83" name="__codelineno-35-83" href="#__codelineno-35-83"></a><span class="w"> </span><span class="n">keys</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="n">total</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">));</span>
|
||||
<a id="__codelineno-35-84" name="__codelineno-35-84" href="#__codelineno-35-84"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">HASHTABLE_CAPACITY</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-85" name="__codelineno-35-85" href="#__codelineno-35-85"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-86" name="__codelineno-35-86" href="#__codelineno-35-86"></a><span class="w"> </span><span class="n">keys</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">key</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-87" name="__codelineno-35-87" href="#__codelineno-35-87"></a><span class="w"> </span><span class="n">index</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-88" name="__codelineno-35-88" href="#__codelineno-35-88"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-89" name="__codelineno-35-89" href="#__codelineno-35-89"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-90" name="__codelineno-35-90" href="#__codelineno-35-90"></a><span class="w"> </span><span class="n">set</span><span class="o">-></span><span class="n">set</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">keys</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-91" name="__codelineno-35-91" href="#__codelineno-35-91"></a><span class="w"> </span><span class="n">set</span><span class="o">-></span><span class="n">len</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">total</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-92" name="__codelineno-35-92" href="#__codelineno-35-92"></a><span class="p">}</span>
|
||||
<a id="__codelineno-35-93" name="__codelineno-35-93" href="#__codelineno-35-93"></a>
|
||||
<a id="__codelineno-35-94" name="__codelineno-35-94" href="#__codelineno-35-94"></a><span class="cm">/* 获取所有值 */</span>
|
||||
<a id="__codelineno-35-95" name="__codelineno-35-95" href="#__codelineno-35-95"></a><span class="kt">void</span><span class="w"> </span><span class="nf">valueSet</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">hmap</span><span class="p">,</span><span class="w"> </span><span class="n">MapSet</span><span class="w"> </span><span class="o">*</span><span class="n">set</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-96" name="__codelineno-35-96" href="#__codelineno-35-96"></a><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">**</span><span class="n">vals</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-97" name="__codelineno-35-97" href="#__codelineno-35-97"></a><span class="w"> </span><span class="kt">int</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="p">,</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-98" name="__codelineno-35-98" href="#__codelineno-35-98"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">total</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-99" name="__codelineno-35-99" href="#__codelineno-35-99"></a><span class="w"> </span><span class="cm">/* 统计有效键值对数量 */</span>
|
||||
<a id="__codelineno-35-100" name="__codelineno-35-100" href="#__codelineno-35-100"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">HASHTABLE_CAPACITY</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-101" name="__codelineno-35-101" href="#__codelineno-35-101"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-102" name="__codelineno-35-102" href="#__codelineno-35-102"></a><span class="w"> </span><span class="n">total</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-103" name="__codelineno-35-103" href="#__codelineno-35-103"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-104" name="__codelineno-35-104" href="#__codelineno-35-104"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-105" name="__codelineno-35-105" href="#__codelineno-35-105"></a><span class="w"> </span><span class="n">vals</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="n">total</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="p">));</span>
|
||||
<a id="__codelineno-35-106" name="__codelineno-35-106" href="#__codelineno-35-106"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">HASHTABLE_CAPACITY</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-107" name="__codelineno-35-107" href="#__codelineno-35-107"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-108" name="__codelineno-35-108" href="#__codelineno-35-108"></a><span class="w"> </span><span class="n">vals</span><span class="p">[</span><span class="n">index</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">hmap</span><span class="o">-></span><span class="n">buckets</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">val</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-109" name="__codelineno-35-109" href="#__codelineno-35-109"></a><span class="w"> </span><span class="n">index</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-110" name="__codelineno-35-110" href="#__codelineno-35-110"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-111" name="__codelineno-35-111" href="#__codelineno-35-111"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-112" name="__codelineno-35-112" href="#__codelineno-35-112"></a><span class="w"> </span><span class="n">set</span><span class="o">-></span><span class="n">set</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">vals</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-113" name="__codelineno-35-113" href="#__codelineno-35-113"></a><span class="w"> </span><span class="n">set</span><span class="o">-></span><span class="n">len</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">total</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-114" name="__codelineno-35-114" href="#__codelineno-35-114"></a><span class="p">}</span>
|
||||
<a id="__codelineno-35-115" name="__codelineno-35-115" href="#__codelineno-35-115"></a>
|
||||
<a id="__codelineno-35-116" name="__codelineno-35-116" href="#__codelineno-35-116"></a><span class="cm">/* 打印哈希表 */</span>
|
||||
<a id="__codelineno-35-117" name="__codelineno-35-117" href="#__codelineno-35-117"></a><span class="kt">void</span><span class="w"> </span><span class="nf">print</span><span class="p">(</span><span class="n">ArrayHashMap</span><span class="w"> </span><span class="o">*</span><span class="n">hmap</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-118" name="__codelineno-35-118" href="#__codelineno-35-118"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-119" name="__codelineno-35-119" href="#__codelineno-35-119"></a><span class="w"> </span><span class="n">MapSet</span><span class="w"> </span><span class="n">set</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-120" name="__codelineno-35-120" href="#__codelineno-35-120"></a><span class="w"> </span><span class="n">pairSet</span><span class="p">(</span><span class="n">hmap</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">set</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-121" name="__codelineno-35-121" href="#__codelineno-35-121"></a><span class="w"> </span><span class="n">Pair</span><span class="w"> </span><span class="o">*</span><span class="n">entries</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">Pair</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">set</span><span class="p">.</span><span class="n">set</span><span class="p">;</span>
|
||||
<a id="__codelineno-35-122" name="__codelineno-35-122" href="#__codelineno-35-122"></a><span class="w"> </span><span class="k">for</span><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">0</span><span class="p">;</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">set</span><span class="p">.</span><span class="n">len</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-35-123" name="__codelineno-35-123" href="#__codelineno-35-123"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"%d -> %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">entries</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">key</span><span class="p">,</span><span class="w"> </span><span class="n">entries</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">val</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-124" name="__codelineno-35-124" href="#__codelineno-35-124"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-35-125" name="__codelineno-35-125" href="#__codelineno-35-125"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">set</span><span class="p">.</span><span class="n">set</span><span class="p">);</span>
|
||||
<a id="__codelineno-35-126" name="__codelineno-35-126" href="#__codelineno-35-126"></a><span class="p">}</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
|
@ -3507,14 +3507,14 @@
|
|||
<div class="highlight"><span class="filename">my_heap.c</span><pre><span></span><code><a id="__codelineno-10-1" name="__codelineno-10-1" href="#__codelineno-10-1"></a><span class="cm">/* 构造函数,根据切片建堆 */</span>
|
||||
<a id="__codelineno-10-2" name="__codelineno-10-2" href="#__codelineno-10-2"></a><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="nf">newMaxHeap</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">nums</span><span class="p">[],</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">size</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-3" name="__codelineno-10-3" href="#__codelineno-10-3"></a><span class="w"> </span><span class="c1">// 所有元素入堆</span>
|
||||
<a id="__codelineno-10-4" name="__codelineno-10-4" href="#__codelineno-10-4"></a><span class="w"> </span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">h</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="n">MaxHeap</span><span class="p">));</span>
|
||||
<a id="__codelineno-10-5" name="__codelineno-10-5" href="#__codelineno-10-5"></a><span class="w"> </span><span class="n">h</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">size</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-6" name="__codelineno-10-6" href="#__codelineno-10-6"></a><span class="w"> </span><span class="n">memcpy</span><span class="p">(</span><span class="n">h</span><span class="o">-></span><span class="n">data</span><span class="p">,</span><span class="w"> </span><span class="n">nums</span><span class="p">,</span><span class="w"> </span><span class="n">size</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">));</span>
|
||||
<a id="__codelineno-10-7" name="__codelineno-10-7" href="#__codelineno-10-7"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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">parent</span><span class="p">(</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="n">size</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="n">i</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">--</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-4" name="__codelineno-10-4" href="#__codelineno-10-4"></a><span class="w"> </span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">maxHeap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="n">MaxHeap</span><span class="p">));</span>
|
||||
<a id="__codelineno-10-5" name="__codelineno-10-5" href="#__codelineno-10-5"></a><span class="w"> </span><span class="n">maxHeap</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">size</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-6" name="__codelineno-10-6" href="#__codelineno-10-6"></a><span class="w"> </span><span class="n">memcpy</span><span class="p">(</span><span class="n">maxHeap</span><span class="o">-></span><span class="n">data</span><span class="p">,</span><span class="w"> </span><span class="n">nums</span><span class="p">,</span><span class="w"> </span><span class="n">size</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">));</span>
|
||||
<a id="__codelineno-10-7" name="__codelineno-10-7" href="#__codelineno-10-7"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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">parent</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="n">size</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="n">i</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">--</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-10-8" name="__codelineno-10-8" href="#__codelineno-10-8"></a><span class="w"> </span><span class="c1">// 堆化除叶节点以外的其他所有节点</span>
|
||||
<a id="__codelineno-10-9" name="__codelineno-10-9" href="#__codelineno-10-9"></a><span class="w"> </span><span class="n">siftDown</span><span class="p">(</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-9" name="__codelineno-10-9" href="#__codelineno-10-9"></a><span class="w"> </span><span class="n">siftDown</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-10" name="__codelineno-10-10" href="#__codelineno-10-10"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-11" name="__codelineno-10-11" href="#__codelineno-10-11"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">h</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-11" name="__codelineno-10-11" href="#__codelineno-10-11"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">maxHeap</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-12" name="__codelineno-10-12" href="#__codelineno-10-12"></a><span class="p">}</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
|
|
|
@ -3967,17 +3967,17 @@
|
|||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">my_heap.c</span><pre><span></span><code><a id="__codelineno-22-1" name="__codelineno-22-1" href="#__codelineno-22-1"></a><span class="cm">/* 获取左子节点索引 */</span>
|
||||
<a id="__codelineno-22-2" name="__codelineno-22-2" href="#__codelineno-22-2"></a><span class="kt">int</span><span class="w"> </span><span class="nf">left</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-2" name="__codelineno-22-2" href="#__codelineno-22-2"></a><span class="kt">int</span><span class="w"> </span><span class="nf">left</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-3" name="__codelineno-22-3" href="#__codelineno-22-3"></a><span class="w"> </span><span class="k">return</span><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><span class="p">;</span>
|
||||
<a id="__codelineno-22-4" name="__codelineno-22-4" href="#__codelineno-22-4"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-5" name="__codelineno-22-5" href="#__codelineno-22-5"></a>
|
||||
<a id="__codelineno-22-6" name="__codelineno-22-6" href="#__codelineno-22-6"></a><span class="cm">/* 获取右子节点索引 */</span>
|
||||
<a id="__codelineno-22-7" name="__codelineno-22-7" href="#__codelineno-22-7"></a><span class="kt">int</span><span class="w"> </span><span class="nf">right</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-7" name="__codelineno-22-7" href="#__codelineno-22-7"></a><span class="kt">int</span><span class="w"> </span><span class="nf">right</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-8" name="__codelineno-22-8" href="#__codelineno-22-8"></a><span class="w"> </span><span class="k">return</span><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><span class="p">;</span>
|
||||
<a id="__codelineno-22-9" name="__codelineno-22-9" href="#__codelineno-22-9"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-10" name="__codelineno-22-10" href="#__codelineno-22-10"></a>
|
||||
<a id="__codelineno-22-11" name="__codelineno-22-11" href="#__codelineno-22-11"></a><span class="cm">/* 获取父节点索引 */</span>
|
||||
<a id="__codelineno-22-12" name="__codelineno-22-12" href="#__codelineno-22-12"></a><span class="kt">int</span><span class="w"> </span><span class="nf">parent</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-12" name="__codelineno-22-12" href="#__codelineno-22-12"></a><span class="kt">int</span><span class="w"> </span><span class="nf">parent</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-13" name="__codelineno-22-13" href="#__codelineno-22-13"></a><span class="w"> </span><span class="k">return</span><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><span class="p">;</span>
|
||||
<a id="__codelineno-22-14" name="__codelineno-22-14" href="#__codelineno-22-14"></a><span class="p">}</span>
|
||||
</code></pre></div>
|
||||
|
@ -4077,8 +4077,8 @@
|
|||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">my_heap.c</span><pre><span></span><code><a id="__codelineno-34-1" name="__codelineno-34-1" href="#__codelineno-34-1"></a><span class="cm">/* 访问堆顶元素 */</span>
|
||||
<a id="__codelineno-34-2" name="__codelineno-34-2" href="#__codelineno-34-2"></a><span class="kt">int</span><span class="w"> </span><span class="nf">peek</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">h</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-3" name="__codelineno-34-3" href="#__codelineno-34-3"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">h</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
|
||||
<a id="__codelineno-34-2" name="__codelineno-34-2" href="#__codelineno-34-2"></a><span class="kt">int</span><span class="w"> </span><span class="nf">peek</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">maxHeap</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-3" name="__codelineno-34-3" href="#__codelineno-34-3"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">maxHeap</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
|
||||
<a id="__codelineno-34-4" name="__codelineno-34-4" href="#__codelineno-34-4"></a><span class="p">}</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
|
@ -4386,31 +4386,31 @@
|
|||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">my_heap.c</span><pre><span></span><code><a id="__codelineno-46-1" name="__codelineno-46-1" href="#__codelineno-46-1"></a><span class="cm">/* 元素入堆 */</span>
|
||||
<a id="__codelineno-46-2" name="__codelineno-46-2" href="#__codelineno-46-2"></a><span class="kt">void</span><span class="w"> </span><span class="nf">push</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">val</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-46-2" name="__codelineno-46-2" href="#__codelineno-46-2"></a><span class="kt">void</span><span class="w"> </span><span class="nf">push</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">val</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-46-3" name="__codelineno-46-3" href="#__codelineno-46-3"></a><span class="w"> </span><span class="c1">// 默认情况下,不应该添加这么多节点</span>
|
||||
<a id="__codelineno-46-4" name="__codelineno-46-4" href="#__codelineno-46-4"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">h</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">MAX_SIZE</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-46-4" name="__codelineno-46-4" href="#__codelineno-46-4"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">maxHeap</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">MAX_SIZE</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-46-5" name="__codelineno-46-5" href="#__codelineno-46-5"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"heap is full!"</span><span class="p">);</span>
|
||||
<a id="__codelineno-46-6" name="__codelineno-46-6" href="#__codelineno-46-6"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-46-7" name="__codelineno-46-7" href="#__codelineno-46-7"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-46-8" name="__codelineno-46-8" href="#__codelineno-46-8"></a><span class="w"> </span><span class="c1">// 添加节点</span>
|
||||
<a id="__codelineno-46-9" name="__codelineno-46-9" href="#__codelineno-46-9"></a><span class="w"> </span><span class="n">h</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">h</span><span class="o">-></span><span class="n">size</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">val</span><span class="p">;</span>
|
||||
<a id="__codelineno-46-10" name="__codelineno-46-10" href="#__codelineno-46-10"></a><span class="w"> </span><span class="n">h</span><span class="o">-></span><span class="n">size</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-46-9" name="__codelineno-46-9" href="#__codelineno-46-9"></a><span class="w"> </span><span class="n">maxHeap</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">maxHeap</span><span class="o">-></span><span class="n">size</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">val</span><span class="p">;</span>
|
||||
<a id="__codelineno-46-10" name="__codelineno-46-10" href="#__codelineno-46-10"></a><span class="w"> </span><span class="n">maxHeap</span><span class="o">-></span><span class="n">size</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-46-11" name="__codelineno-46-11" href="#__codelineno-46-11"></a>
|
||||
<a id="__codelineno-46-12" name="__codelineno-46-12" href="#__codelineno-46-12"></a><span class="w"> </span><span class="c1">// 从底至顶堆化</span>
|
||||
<a id="__codelineno-46-13" name="__codelineno-46-13" href="#__codelineno-46-13"></a><span class="w"> </span><span class="n">siftUp</span><span class="p">(</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="n">h</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>
|
||||
<a id="__codelineno-46-13" name="__codelineno-46-13" href="#__codelineno-46-13"></a><span class="w"> </span><span class="n">siftUp</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="n">maxHeap</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>
|
||||
<a id="__codelineno-46-14" name="__codelineno-46-14" href="#__codelineno-46-14"></a><span class="p">}</span>
|
||||
<a id="__codelineno-46-15" name="__codelineno-46-15" href="#__codelineno-46-15"></a>
|
||||
<a id="__codelineno-46-16" name="__codelineno-46-16" href="#__codelineno-46-16"></a><span class="cm">/* 从节点 i 开始,从底至顶堆化 */</span>
|
||||
<a id="__codelineno-46-17" name="__codelineno-46-17" href="#__codelineno-46-17"></a><span class="kt">void</span><span class="w"> </span><span class="nf">siftUp</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-46-17" name="__codelineno-46-17" href="#__codelineno-46-17"></a><span class="kt">void</span><span class="w"> </span><span class="nf">siftUp</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-46-18" name="__codelineno-46-18" href="#__codelineno-46-18"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="nb">true</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-46-19" name="__codelineno-46-19" href="#__codelineno-46-19"></a><span class="w"> </span><span class="c1">// 获取节点 i 的父节点</span>
|
||||
<a id="__codelineno-46-20" name="__codelineno-46-20" href="#__codelineno-46-20"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">parent</span><span class="p">(</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-46-20" name="__codelineno-46-20" href="#__codelineno-46-20"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">parent</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-46-21" name="__codelineno-46-21" href="#__codelineno-46-21"></a><span class="w"> </span><span class="c1">// 当“越过根节点”或“节点无须修复”时,结束堆化</span>
|
||||
<a id="__codelineno-46-22" name="__codelineno-46-22" href="#__codelineno-46-22"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">p</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">h</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="n">h</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">p</span><span class="p">])</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-46-22" name="__codelineno-46-22" href="#__codelineno-46-22"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">p</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">maxHeap</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o"><=</span><span class="w"> </span><span class="n">maxHeap</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">p</span><span class="p">])</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-46-23" name="__codelineno-46-23" href="#__codelineno-46-23"></a><span class="w"> </span><span class="k">break</span><span class="p">;</span>
|
||||
<a id="__codelineno-46-24" name="__codelineno-46-24" href="#__codelineno-46-24"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-46-25" name="__codelineno-46-25" href="#__codelineno-46-25"></a><span class="w"> </span><span class="c1">// 交换两节点</span>
|
||||
<a id="__codelineno-46-26" name="__codelineno-46-26" href="#__codelineno-46-26"></a><span class="w"> </span><span class="n">swap</span><span class="p">(</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">);</span>
|
||||
<a id="__codelineno-46-26" name="__codelineno-46-26" href="#__codelineno-46-26"></a><span class="w"> </span><span class="n">swap</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">);</span>
|
||||
<a id="__codelineno-46-27" name="__codelineno-46-27" href="#__codelineno-46-27"></a><span class="w"> </span><span class="c1">// 循环向上堆化</span>
|
||||
<a id="__codelineno-46-28" name="__codelineno-46-28" href="#__codelineno-46-28"></a><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p</span><span class="p">;</span>
|
||||
<a id="__codelineno-46-29" name="__codelineno-46-29" href="#__codelineno-46-29"></a><span class="w"> </span><span class="p">}</span>
|
||||
|
@ -4860,35 +4860,35 @@
|
|||
</div>
|
||||
<div class="tabbed-block">
|
||||
<div class="highlight"><span class="filename">my_heap.c</span><pre><span></span><code><a id="__codelineno-58-1" name="__codelineno-58-1" href="#__codelineno-58-1"></a><span class="cm">/* 元素出堆 */</span>
|
||||
<a id="__codelineno-58-2" name="__codelineno-58-2" href="#__codelineno-58-2"></a><span class="kt">int</span><span class="w"> </span><span class="nf">pop</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">h</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-58-2" name="__codelineno-58-2" href="#__codelineno-58-2"></a><span class="kt">int</span><span class="w"> </span><span class="nf">pop</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">maxHeap</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-58-3" name="__codelineno-58-3" href="#__codelineno-58-3"></a><span class="w"> </span><span class="c1">// 判空处理</span>
|
||||
<a id="__codelineno-58-4" name="__codelineno-58-4" href="#__codelineno-58-4"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">isEmpty</span><span class="p">(</span><span class="n">h</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-58-4" name="__codelineno-58-4" href="#__codelineno-58-4"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">isEmpty</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-58-5" name="__codelineno-58-5" href="#__codelineno-58-5"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"heap is empty!"</span><span class="p">);</span>
|
||||
<a id="__codelineno-58-6" name="__codelineno-58-6" href="#__codelineno-58-6"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">INT_MAX</span><span class="p">;</span>
|
||||
<a id="__codelineno-58-7" name="__codelineno-58-7" href="#__codelineno-58-7"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-58-8" name="__codelineno-58-8" href="#__codelineno-58-8"></a><span class="w"> </span><span class="c1">// 交换根节点与最右叶节点(即交换首元素与尾元素)</span>
|
||||
<a id="__codelineno-58-9" name="__codelineno-58-9" href="#__codelineno-58-9"></a><span class="w"> </span><span class="n">swap</span><span class="p">(</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">h</span><span class="p">)</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>
|
||||
<a id="__codelineno-58-9" name="__codelineno-58-9" href="#__codelineno-58-9"></a><span class="w"> </span><span class="n">swap</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">)</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span>
|
||||
<a id="__codelineno-58-10" name="__codelineno-58-10" href="#__codelineno-58-10"></a><span class="w"> </span><span class="c1">// 删除节点</span>
|
||||
<a id="__codelineno-58-11" name="__codelineno-58-11" href="#__codelineno-58-11"></a><span class="w"> </span><span class="kt">int</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">h</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">h</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">];</span>
|
||||
<a id="__codelineno-58-12" name="__codelineno-58-12" href="#__codelineno-58-12"></a><span class="w"> </span><span class="n">h</span><span class="o">-></span><span class="n">size</span><span class="o">--</span><span class="p">;</span>
|
||||
<a id="__codelineno-58-11" name="__codelineno-58-11" href="#__codelineno-58-11"></a><span class="w"> </span><span class="kt">int</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">maxHeap</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">maxHeap</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">];</span>
|
||||
<a id="__codelineno-58-12" name="__codelineno-58-12" href="#__codelineno-58-12"></a><span class="w"> </span><span class="n">maxHeap</span><span class="o">-></span><span class="n">size</span><span class="o">--</span><span class="p">;</span>
|
||||
<a id="__codelineno-58-13" name="__codelineno-58-13" href="#__codelineno-58-13"></a><span class="w"> </span><span class="c1">// 从顶至底堆化</span>
|
||||
<a id="__codelineno-58-14" name="__codelineno-58-14" href="#__codelineno-58-14"></a><span class="w"> </span><span class="n">siftDown</span><span class="p">(</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">);</span>
|
||||
<a id="__codelineno-58-14" name="__codelineno-58-14" href="#__codelineno-58-14"></a><span class="w"> </span><span class="n">siftDown</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">);</span>
|
||||
<a id="__codelineno-58-15" name="__codelineno-58-15" href="#__codelineno-58-15"></a>
|
||||
<a id="__codelineno-58-16" name="__codelineno-58-16" href="#__codelineno-58-16"></a><span class="w"> </span><span class="c1">// 返回堆顶元素</span>
|
||||
<a id="__codelineno-58-17" name="__codelineno-58-17" href="#__codelineno-58-17"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">val</span><span class="p">;</span>
|
||||
<a id="__codelineno-58-18" name="__codelineno-58-18" href="#__codelineno-58-18"></a><span class="p">}</span>
|
||||
<a id="__codelineno-58-19" name="__codelineno-58-19" href="#__codelineno-58-19"></a>
|
||||
<a id="__codelineno-58-20" name="__codelineno-58-20" href="#__codelineno-58-20"></a><span class="cm">/* 从节点 i 开始,从顶至底堆化 */</span>
|
||||
<a id="__codelineno-58-21" name="__codelineno-58-21" href="#__codelineno-58-21"></a><span class="kt">void</span><span class="w"> </span><span class="nf">siftDown</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-58-21" name="__codelineno-58-21" href="#__codelineno-58-21"></a><span class="kt">void</span><span class="w"> </span><span class="nf">siftDown</span><span class="p">(</span><span class="n">MaxHeap</span><span class="w"> </span><span class="o">*</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-58-22" name="__codelineno-58-22" href="#__codelineno-58-22"></a><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="nb">true</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-58-23" name="__codelineno-58-23" href="#__codelineno-58-23"></a><span class="w"> </span><span class="c1">// 判断节点 i, l, r 中值最大的节点,记为 max</span>
|
||||
<a id="__codelineno-58-24" name="__codelineno-58-24" href="#__codelineno-58-24"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">l</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">left</span><span class="p">(</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-58-25" name="__codelineno-58-25" href="#__codelineno-58-25"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">r</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">right</span><span class="p">(</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-58-24" name="__codelineno-58-24" href="#__codelineno-58-24"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">l</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">left</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-58-25" name="__codelineno-58-25" href="#__codelineno-58-25"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">r</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">right</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-58-26" name="__codelineno-58-26" href="#__codelineno-58-26"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">max</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">i</span><span class="p">;</span>
|
||||
<a id="__codelineno-58-27" name="__codelineno-58-27" href="#__codelineno-58-27"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">l</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">h</span><span class="p">)</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="n">h</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">l</span><span class="p">]</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="n">h</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">max</span><span class="p">])</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-58-27" name="__codelineno-58-27" href="#__codelineno-58-27"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">l</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">)</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="n">maxHeap</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">l</span><span class="p">]</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="n">maxHeap</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">max</span><span class="p">])</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-58-28" name="__codelineno-58-28" href="#__codelineno-58-28"></a><span class="w"> </span><span class="n">max</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">l</span><span class="p">;</span>
|
||||
<a id="__codelineno-58-29" name="__codelineno-58-29" href="#__codelineno-58-29"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-58-30" name="__codelineno-58-30" href="#__codelineno-58-30"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">r</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">h</span><span class="p">)</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="n">h</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">r</span><span class="p">]</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="n">h</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">max</span><span class="p">])</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-58-30" name="__codelineno-58-30" href="#__codelineno-58-30"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">r</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">)</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="n">maxHeap</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">r</span><span class="p">]</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="n">maxHeap</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">max</span><span class="p">])</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-58-31" name="__codelineno-58-31" href="#__codelineno-58-31"></a><span class="w"> </span><span class="n">max</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">r</span><span class="p">;</span>
|
||||
<a id="__codelineno-58-32" name="__codelineno-58-32" href="#__codelineno-58-32"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-58-33" name="__codelineno-58-33" href="#__codelineno-58-33"></a><span class="w"> </span><span class="c1">// 若节点 i 最大或索引 l, r 越界,则无须继续堆化,跳出</span>
|
||||
|
@ -4896,7 +4896,7 @@
|
|||
<a id="__codelineno-58-35" name="__codelineno-58-35" href="#__codelineno-58-35"></a><span class="w"> </span><span class="k">break</span><span class="p">;</span>
|
||||
<a id="__codelineno-58-36" name="__codelineno-58-36" href="#__codelineno-58-36"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-58-37" name="__codelineno-58-37" href="#__codelineno-58-37"></a><span class="w"> </span><span class="c1">// 交换两节点</span>
|
||||
<a id="__codelineno-58-38" name="__codelineno-58-38" href="#__codelineno-58-38"></a><span class="w"> </span><span class="n">swap</span><span class="p">(</span><span class="n">h</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">max</span><span class="p">);</span>
|
||||
<a id="__codelineno-58-38" name="__codelineno-58-38" href="#__codelineno-58-38"></a><span class="w"> </span><span class="n">swap</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">max</span><span class="p">);</span>
|
||||
<a id="__codelineno-58-39" name="__codelineno-58-39" href="#__codelineno-58-39"></a><span class="w"> </span><span class="c1">// 循环向下堆化</span>
|
||||
<a id="__codelineno-58-40" name="__codelineno-58-40" href="#__codelineno-58-40"></a><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">max</span><span class="p">;</span>
|
||||
<a id="__codelineno-58-41" name="__codelineno-58-41" href="#__codelineno-58-41"></a><span class="w"> </span><span class="p">}</span>
|
||||
|
|
|
@ -3742,7 +3742,7 @@
|
|||
<a id="__codelineno-10-56" name="__codelineno-10-56" href="#__codelineno-10-56"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-10-57" name="__codelineno-10-57" href="#__codelineno-10-57"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">getMinHeap</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-58" name="__codelineno-10-58" href="#__codelineno-10-58"></a><span class="w"> </span><span class="c1">// 释放内存</span>
|
||||
<a id="__codelineno-10-59" name="__codelineno-10-59" href="#__codelineno-10-59"></a><span class="w"> </span><span class="n">freeMaxHeap</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-59" name="__codelineno-10-59" href="#__codelineno-10-59"></a><span class="w"> </span><span class="n">delMaxHeap</span><span class="p">(</span><span class="n">maxHeap</span><span class="p">);</span>
|
||||
<a id="__codelineno-10-60" name="__codelineno-10-60" href="#__codelineno-10-60"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">res</span><span class="p">;</span>
|
||||
<a id="__codelineno-10-61" name="__codelineno-10-61" href="#__codelineno-10-61"></a><span class="p">}</span>
|
||||
</code></pre></div>
|
||||
|
|
|
@ -6500,7 +6500,7 @@
|
|||
<a id="__codelineno-34-19" name="__codelineno-34-19" href="#__codelineno-34-19"></a><span class="cm">/* 析构函数 */</span>
|
||||
<a id="__codelineno-34-20" name="__codelineno-34-20" href="#__codelineno-34-20"></a><span class="kt">void</span><span class="w"> </span><span class="nf">delArrayDeque</span><span class="p">(</span><span class="n">ArrayDeque</span><span class="w"> </span><span class="o">*</span><span class="n">deque</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-21" name="__codelineno-34-21" href="#__codelineno-34-21"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">deque</span><span class="o">-></span><span class="n">nums</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-22" name="__codelineno-34-22" href="#__codelineno-34-22"></a><span class="w"> </span><span class="n">deque</span><span class="o">-></span><span class="n">queCapacity</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-22" name="__codelineno-34-22" href="#__codelineno-34-22"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">deque</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-23" name="__codelineno-34-23" href="#__codelineno-34-23"></a><span class="p">}</span>
|
||||
<a id="__codelineno-34-24" name="__codelineno-34-24" href="#__codelineno-34-24"></a>
|
||||
<a id="__codelineno-34-25" name="__codelineno-34-25" href="#__codelineno-34-25"></a><span class="cm">/* 获取双向队列的容量 */</span>
|
||||
|
|
|
@ -5323,7 +5323,7 @@
|
|||
<a id="__codelineno-34-19" name="__codelineno-34-19" href="#__codelineno-34-19"></a><span class="cm">/* 析构函数 */</span>
|
||||
<a id="__codelineno-34-20" name="__codelineno-34-20" href="#__codelineno-34-20"></a><span class="kt">void</span><span class="w"> </span><span class="nf">delArrayQueue</span><span class="p">(</span><span class="n">ArrayQueue</span><span class="w"> </span><span class="o">*</span><span class="n">queue</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-21" name="__codelineno-34-21" href="#__codelineno-34-21"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">queue</span><span class="o">-></span><span class="n">nums</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-22" name="__codelineno-34-22" href="#__codelineno-34-22"></a><span class="w"> </span><span class="n">queue</span><span class="o">-></span><span class="n">queCapacity</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-22" name="__codelineno-34-22" href="#__codelineno-34-22"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">queue</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-23" name="__codelineno-34-23" href="#__codelineno-34-23"></a><span class="p">}</span>
|
||||
<a id="__codelineno-34-24" name="__codelineno-34-24" href="#__codelineno-34-24"></a>
|
||||
<a id="__codelineno-34-25" name="__codelineno-34-25" href="#__codelineno-34-25"></a><span class="cm">/* 获取队列的容量 */</span>
|
||||
|
|
|
@ -4946,52 +4946,58 @@
|
|||
<a id="__codelineno-34-6" name="__codelineno-34-6" href="#__codelineno-34-6"></a>
|
||||
<a id="__codelineno-34-7" name="__codelineno-34-7" href="#__codelineno-34-7"></a><span class="cm">/* 构造函数 */</span>
|
||||
<a id="__codelineno-34-8" name="__codelineno-34-8" href="#__codelineno-34-8"></a><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="nf">newArrayStack</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-9" name="__codelineno-34-9" href="#__codelineno-34-9"></a><span class="w"> </span><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="n">ArrayStack</span><span class="p">));</span>
|
||||
<a id="__codelineno-34-9" name="__codelineno-34-9" href="#__codelineno-34-9"></a><span class="w"> </span><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="n">stack</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="n">ArrayStack</span><span class="p">));</span>
|
||||
<a id="__codelineno-34-10" name="__codelineno-34-10" href="#__codelineno-34-10"></a><span class="w"> </span><span class="c1">// 初始化一个大容量,避免扩容</span>
|
||||
<a id="__codelineno-34-11" name="__codelineno-34-11" href="#__codelineno-34-11"></a><span class="w"> </span><span class="n">s</span><span class="o">-></span><span class="n">data</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_SIZE</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-12" name="__codelineno-34-12" href="#__codelineno-34-12"></a><span class="w"> </span><span class="n">s</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-13" name="__codelineno-34-13" href="#__codelineno-34-13"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">s</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-11" name="__codelineno-34-11" href="#__codelineno-34-11"></a><span class="w"> </span><span class="n">stack</span><span class="o">-></span><span class="n">data</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">MAX_SIZE</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-12" name="__codelineno-34-12" href="#__codelineno-34-12"></a><span class="w"> </span><span class="n">stack</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-13" name="__codelineno-34-13" href="#__codelineno-34-13"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">stack</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-14" name="__codelineno-34-14" href="#__codelineno-34-14"></a><span class="p">}</span>
|
||||
<a id="__codelineno-34-15" name="__codelineno-34-15" href="#__codelineno-34-15"></a>
|
||||
<a id="__codelineno-34-16" name="__codelineno-34-16" href="#__codelineno-34-16"></a><span class="cm">/* 获取栈的长度 */</span>
|
||||
<a id="__codelineno-34-17" name="__codelineno-34-17" href="#__codelineno-34-17"></a><span class="kt">int</span><span class="w"> </span><span class="nf">size</span><span class="p">(</span><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="n">s</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-18" name="__codelineno-34-18" href="#__codelineno-34-18"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">s</span><span class="o">-></span><span class="n">size</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-19" name="__codelineno-34-19" href="#__codelineno-34-19"></a><span class="p">}</span>
|
||||
<a id="__codelineno-34-20" name="__codelineno-34-20" href="#__codelineno-34-20"></a>
|
||||
<a id="__codelineno-34-21" name="__codelineno-34-21" href="#__codelineno-34-21"></a><span class="cm">/* 判断栈是否为空 */</span>
|
||||
<a id="__codelineno-34-22" name="__codelineno-34-22" href="#__codelineno-34-22"></a><span class="kt">bool</span><span class="w"> </span><span class="nf">isEmpty</span><span class="p">(</span><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="n">s</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-23" name="__codelineno-34-23" href="#__codelineno-34-23"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">s</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-24" name="__codelineno-34-24" href="#__codelineno-34-24"></a><span class="p">}</span>
|
||||
<a id="__codelineno-34-25" name="__codelineno-34-25" href="#__codelineno-34-25"></a>
|
||||
<a id="__codelineno-34-26" name="__codelineno-34-26" href="#__codelineno-34-26"></a><span class="cm">/* 入栈 */</span>
|
||||
<a id="__codelineno-34-27" name="__codelineno-34-27" href="#__codelineno-34-27"></a><span class="kt">void</span><span class="w"> </span><span class="nf">push</span><span class="p">(</span><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="n">s</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">num</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-28" name="__codelineno-34-28" href="#__codelineno-34-28"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">MAX_SIZE</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-29" name="__codelineno-34-29" href="#__codelineno-34-29"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"stack is full.</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-30" name="__codelineno-34-30" href="#__codelineno-34-30"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-31" name="__codelineno-34-31" href="#__codelineno-34-31"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-34-32" name="__codelineno-34-32" href="#__codelineno-34-32"></a><span class="w"> </span><span class="n">s</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">s</span><span class="o">-></span><span class="n">size</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">num</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-33" name="__codelineno-34-33" href="#__codelineno-34-33"></a><span class="w"> </span><span class="n">s</span><span class="o">-></span><span class="n">size</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-34" name="__codelineno-34-34" href="#__codelineno-34-34"></a><span class="p">}</span>
|
||||
<a id="__codelineno-34-35" name="__codelineno-34-35" href="#__codelineno-34-35"></a>
|
||||
<a id="__codelineno-34-36" name="__codelineno-34-36" href="#__codelineno-34-36"></a><span class="cm">/* 访问栈顶元素 */</span>
|
||||
<a id="__codelineno-34-37" name="__codelineno-34-37" href="#__codelineno-34-37"></a><span class="kt">int</span><span class="w"> </span><span class="nf">peek</span><span class="p">(</span><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="n">s</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-38" name="__codelineno-34-38" href="#__codelineno-34-38"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-39" name="__codelineno-34-39" href="#__codelineno-34-39"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"stack is empty.</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-40" name="__codelineno-34-40" href="#__codelineno-34-40"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">INT_MAX</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-41" name="__codelineno-34-41" href="#__codelineno-34-41"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-34-42" name="__codelineno-34-42" href="#__codelineno-34-42"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">s</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">s</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">];</span>
|
||||
<a id="__codelineno-34-43" name="__codelineno-34-43" href="#__codelineno-34-43"></a><span class="p">}</span>
|
||||
<a id="__codelineno-34-44" name="__codelineno-34-44" href="#__codelineno-34-44"></a>
|
||||
<a id="__codelineno-34-45" name="__codelineno-34-45" href="#__codelineno-34-45"></a><span class="cm">/* 出栈 */</span>
|
||||
<a id="__codelineno-34-46" name="__codelineno-34-46" href="#__codelineno-34-46"></a><span class="kt">int</span><span class="w"> </span><span class="nf">pop</span><span class="p">(</span><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="n">s</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-47" name="__codelineno-34-47" href="#__codelineno-34-47"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">s</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-48" name="__codelineno-34-48" href="#__codelineno-34-48"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"stack is empty.</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-49" name="__codelineno-34-49" href="#__codelineno-34-49"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">INT_MAX</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-50" name="__codelineno-34-50" href="#__codelineno-34-50"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-34-51" name="__codelineno-34-51" href="#__codelineno-34-51"></a><span class="w"> </span><span class="kt">int</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">peek</span><span class="p">(</span><span class="n">s</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-52" name="__codelineno-34-52" href="#__codelineno-34-52"></a><span class="w"> </span><span class="n">s</span><span class="o">-></span><span class="n">size</span><span class="o">--</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-53" name="__codelineno-34-53" href="#__codelineno-34-53"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">val</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-54" name="__codelineno-34-54" href="#__codelineno-34-54"></a><span class="p">}</span>
|
||||
<a id="__codelineno-34-16" name="__codelineno-34-16" href="#__codelineno-34-16"></a><span class="cm">/* 析构函数 */</span>
|
||||
<a id="__codelineno-34-17" name="__codelineno-34-17" href="#__codelineno-34-17"></a><span class="kt">void</span><span class="w"> </span><span class="nf">delArrayStack</span><span class="p">(</span><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="n">stack</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-18" name="__codelineno-34-18" href="#__codelineno-34-18"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">stack</span><span class="o">-></span><span class="n">data</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-19" name="__codelineno-34-19" href="#__codelineno-34-19"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">stack</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-20" name="__codelineno-34-20" href="#__codelineno-34-20"></a><span class="p">}</span>
|
||||
<a id="__codelineno-34-21" name="__codelineno-34-21" href="#__codelineno-34-21"></a>
|
||||
<a id="__codelineno-34-22" name="__codelineno-34-22" href="#__codelineno-34-22"></a><span class="cm">/* 获取栈的长度 */</span>
|
||||
<a id="__codelineno-34-23" name="__codelineno-34-23" href="#__codelineno-34-23"></a><span class="kt">int</span><span class="w"> </span><span class="nf">size</span><span class="p">(</span><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="n">stack</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-24" name="__codelineno-34-24" href="#__codelineno-34-24"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">stack</span><span class="o">-></span><span class="n">size</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-25" name="__codelineno-34-25" href="#__codelineno-34-25"></a><span class="p">}</span>
|
||||
<a id="__codelineno-34-26" name="__codelineno-34-26" href="#__codelineno-34-26"></a>
|
||||
<a id="__codelineno-34-27" name="__codelineno-34-27" href="#__codelineno-34-27"></a><span class="cm">/* 判断栈是否为空 */</span>
|
||||
<a id="__codelineno-34-28" name="__codelineno-34-28" href="#__codelineno-34-28"></a><span class="kt">bool</span><span class="w"> </span><span class="nf">isEmpty</span><span class="p">(</span><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="n">stack</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-29" name="__codelineno-34-29" href="#__codelineno-34-29"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">stack</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-30" name="__codelineno-34-30" href="#__codelineno-34-30"></a><span class="p">}</span>
|
||||
<a id="__codelineno-34-31" name="__codelineno-34-31" href="#__codelineno-34-31"></a>
|
||||
<a id="__codelineno-34-32" name="__codelineno-34-32" href="#__codelineno-34-32"></a><span class="cm">/* 入栈 */</span>
|
||||
<a id="__codelineno-34-33" name="__codelineno-34-33" href="#__codelineno-34-33"></a><span class="kt">void</span><span class="w"> </span><span class="nf">push</span><span class="p">(</span><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="n">stack</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">num</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-34" name="__codelineno-34-34" href="#__codelineno-34-34"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">stack</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">MAX_SIZE</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-35" name="__codelineno-34-35" href="#__codelineno-34-35"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"stack is full.</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-36" name="__codelineno-34-36" href="#__codelineno-34-36"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-37" name="__codelineno-34-37" href="#__codelineno-34-37"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-34-38" name="__codelineno-34-38" href="#__codelineno-34-38"></a><span class="w"> </span><span class="n">stack</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">stack</span><span class="o">-></span><span class="n">size</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">num</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-39" name="__codelineno-34-39" href="#__codelineno-34-39"></a><span class="w"> </span><span class="n">stack</span><span class="o">-></span><span class="n">size</span><span class="o">++</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-40" name="__codelineno-34-40" href="#__codelineno-34-40"></a><span class="p">}</span>
|
||||
<a id="__codelineno-34-41" name="__codelineno-34-41" href="#__codelineno-34-41"></a>
|
||||
<a id="__codelineno-34-42" name="__codelineno-34-42" href="#__codelineno-34-42"></a><span class="cm">/* 访问栈顶元素 */</span>
|
||||
<a id="__codelineno-34-43" name="__codelineno-34-43" href="#__codelineno-34-43"></a><span class="kt">int</span><span class="w"> </span><span class="nf">peek</span><span class="p">(</span><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="n">stack</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-44" name="__codelineno-34-44" href="#__codelineno-34-44"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">stack</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-45" name="__codelineno-34-45" href="#__codelineno-34-45"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"stack is empty.</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-46" name="__codelineno-34-46" href="#__codelineno-34-46"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">INT_MAX</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-47" name="__codelineno-34-47" href="#__codelineno-34-47"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-34-48" name="__codelineno-34-48" href="#__codelineno-34-48"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">stack</span><span class="o">-></span><span class="n">data</span><span class="p">[</span><span class="n">stack</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">];</span>
|
||||
<a id="__codelineno-34-49" name="__codelineno-34-49" href="#__codelineno-34-49"></a><span class="p">}</span>
|
||||
<a id="__codelineno-34-50" name="__codelineno-34-50" href="#__codelineno-34-50"></a>
|
||||
<a id="__codelineno-34-51" name="__codelineno-34-51" href="#__codelineno-34-51"></a><span class="cm">/* 出栈 */</span>
|
||||
<a id="__codelineno-34-52" name="__codelineno-34-52" href="#__codelineno-34-52"></a><span class="kt">int</span><span class="w"> </span><span class="nf">pop</span><span class="p">(</span><span class="n">ArrayStack</span><span class="w"> </span><span class="o">*</span><span class="n">stack</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-53" name="__codelineno-34-53" href="#__codelineno-34-53"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">stack</span><span class="o">-></span><span class="n">size</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-34-54" name="__codelineno-34-54" href="#__codelineno-34-54"></a><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"stack is empty.</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-55" name="__codelineno-34-55" href="#__codelineno-34-55"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">INT_MAX</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-56" name="__codelineno-34-56" href="#__codelineno-34-56"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-34-57" name="__codelineno-34-57" href="#__codelineno-34-57"></a><span class="w"> </span><span class="kt">int</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">peek</span><span class="p">(</span><span class="n">stack</span><span class="p">);</span>
|
||||
<a id="__codelineno-34-58" name="__codelineno-34-58" href="#__codelineno-34-58"></a><span class="w"> </span><span class="n">stack</span><span class="o">-></span><span class="n">size</span><span class="o">--</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-59" name="__codelineno-34-59" href="#__codelineno-34-59"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">val</span><span class="p">;</span>
|
||||
<a id="__codelineno-34-60" name="__codelineno-34-60" href="#__codelineno-34-60"></a><span class="p">}</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
|
@ -4380,7 +4380,7 @@
|
|||
<a id="__codelineno-22-5" name="__codelineno-22-5" href="#__codelineno-22-5"></a><span class="p">}</span><span class="w"> </span><span class="n">ArrayBinaryTree</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-6" name="__codelineno-22-6" href="#__codelineno-22-6"></a>
|
||||
<a id="__codelineno-22-7" name="__codelineno-22-7" href="#__codelineno-22-7"></a><span class="cm">/* 构造函数 */</span>
|
||||
<a id="__codelineno-22-8" name="__codelineno-22-8" href="#__codelineno-22-8"></a><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="nf">createArrayBinaryTree</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">arr</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">arrSize</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-8" name="__codelineno-22-8" href="#__codelineno-22-8"></a><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="nf">newArrayBinaryTree</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">arr</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">arrSize</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-9" name="__codelineno-22-9" href="#__codelineno-22-9"></a><span class="w"> </span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="p">));</span>
|
||||
<a id="__codelineno-22-10" name="__codelineno-22-10" href="#__codelineno-22-10"></a><span class="w"> </span><span class="n">abt</span><span class="o">-></span><span class="n">tree</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">arrSize</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-11" name="__codelineno-22-11" href="#__codelineno-22-11"></a><span class="w"> </span><span class="n">memcpy</span><span class="p">(</span><span class="n">abt</span><span class="o">-></span><span class="n">tree</span><span class="p">,</span><span class="w"> </span><span class="n">arr</span><span class="p">,</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">arrSize</span><span class="p">);</span>
|
||||
|
@ -4388,76 +4388,82 @@
|
|||
<a id="__codelineno-22-13" name="__codelineno-22-13" href="#__codelineno-22-13"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">abt</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-14" name="__codelineno-22-14" href="#__codelineno-22-14"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-15" name="__codelineno-22-15" href="#__codelineno-22-15"></a>
|
||||
<a id="__codelineno-22-16" name="__codelineno-22-16" href="#__codelineno-22-16"></a><span class="cm">/* 节点数量 */</span>
|
||||
<a id="__codelineno-22-17" name="__codelineno-22-17" href="#__codelineno-22-17"></a><span class="kt">int</span><span class="w"> </span><span class="nf">size</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-18" name="__codelineno-22-18" href="#__codelineno-22-18"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">abt</span><span class="o">-></span><span class="n">size</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-19" name="__codelineno-22-19" href="#__codelineno-22-19"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-20" name="__codelineno-22-20" href="#__codelineno-22-20"></a>
|
||||
<a id="__codelineno-22-21" name="__codelineno-22-21" href="#__codelineno-22-21"></a><span class="cm">/* 获取索引为 i 节点的值 */</span>
|
||||
<a id="__codelineno-22-22" name="__codelineno-22-22" href="#__codelineno-22-22"></a><span class="kt">int</span><span class="w"> </span><span class="nf">val</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-23" name="__codelineno-22-23" href="#__codelineno-22-23"></a><span class="w"> </span><span class="c1">// 若索引越界,则返回 INT_MAX ,代表空位</span>
|
||||
<a id="__codelineno-22-24" name="__codelineno-22-24" href="#__codelineno-22-24"></a><span class="w"> </span><span class="k">if</span><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">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><span class="p">(</span><span class="n">abt</span><span class="p">))</span>
|
||||
<a id="__codelineno-22-25" name="__codelineno-22-25" href="#__codelineno-22-25"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">INT_MAX</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-26" name="__codelineno-22-26" href="#__codelineno-22-26"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">abt</span><span class="o">-></span><span class="n">tree</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
|
||||
<a id="__codelineno-22-27" name="__codelineno-22-27" href="#__codelineno-22-27"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-28" name="__codelineno-22-28" href="#__codelineno-22-28"></a>
|
||||
<a id="__codelineno-22-29" name="__codelineno-22-29" href="#__codelineno-22-29"></a><span class="cm">/* 层序遍历 */</span>
|
||||
<a id="__codelineno-22-30" name="__codelineno-22-30" href="#__codelineno-22-30"></a><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="nf">levelOrder</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-31" name="__codelineno-22-31" href="#__codelineno-22-31"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">abt</span><span class="p">));</span>
|
||||
<a id="__codelineno-22-32" name="__codelineno-22-32" href="#__codelineno-22-32"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-33" name="__codelineno-22-33" href="#__codelineno-22-33"></a><span class="w"> </span><span class="c1">// 直接遍历数组</span>
|
||||
<a id="__codelineno-22-34" name="__codelineno-22-34" href="#__codelineno-22-34"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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="p">;</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><span class="p">(</span><span class="n">abt</span><span class="p">);</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-35" name="__codelineno-22-35" href="#__codelineno-22-35"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">val</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">INT_MAX</span><span class="p">)</span>
|
||||
<a id="__codelineno-22-36" name="__codelineno-22-36" href="#__codelineno-22-36"></a><span class="w"> </span><span class="n">res</span><span class="p">[</span><span class="n">index</span><span class="o">++</span><span class="p">]</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">abt</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-37" name="__codelineno-22-37" href="#__codelineno-22-37"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-22-38" name="__codelineno-22-38" href="#__codelineno-22-38"></a><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">index</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-39" name="__codelineno-22-39" href="#__codelineno-22-39"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">res</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-40" name="__codelineno-22-40" href="#__codelineno-22-40"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-41" name="__codelineno-22-41" href="#__codelineno-22-41"></a>
|
||||
<a id="__codelineno-22-42" name="__codelineno-22-42" href="#__codelineno-22-42"></a><span class="cm">/* 深度优先遍历 */</span>
|
||||
<a id="__codelineno-22-43" name="__codelineno-22-43" href="#__codelineno-22-43"></a><span class="kt">void</span><span class="w"> </span><span class="nf">dfs</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">order</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">index</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-44" name="__codelineno-22-44" href="#__codelineno-22-44"></a><span class="w"> </span><span class="c1">// 若为空位,则返回</span>
|
||||
<a id="__codelineno-22-45" name="__codelineno-22-45" href="#__codelineno-22-45"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">val</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">INT_MAX</span><span class="p">)</span>
|
||||
<a id="__codelineno-22-46" name="__codelineno-22-46" href="#__codelineno-22-46"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-47" name="__codelineno-22-47" href="#__codelineno-22-47"></a><span class="w"> </span><span class="c1">// 前序遍历</span>
|
||||
<a id="__codelineno-22-48" name="__codelineno-22-48" href="#__codelineno-22-48"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">strcmp</span><span class="p">(</span><span class="n">order</span><span class="p">,</span><span class="w"> </span><span class="s">"pre"</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span>
|
||||
<a id="__codelineno-22-49" name="__codelineno-22-49" href="#__codelineno-22-49"></a><span class="w"> </span><span class="n">res</span><span class="p">[(</span><span class="o">*</span><span class="n">index</span><span class="p">)</span><span class="o">++</span><span class="p">]</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">abt</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-50" name="__codelineno-22-50" href="#__codelineno-22-50"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </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><span class="w"> </span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="n">index</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-51" name="__codelineno-22-51" href="#__codelineno-22-51"></a><span class="w"> </span><span class="c1">// 中序遍历</span>
|
||||
<a id="__codelineno-22-52" name="__codelineno-22-52" href="#__codelineno-22-52"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">strcmp</span><span class="p">(</span><span class="n">order</span><span class="p">,</span><span class="w"> </span><span class="s">"in"</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span>
|
||||
<a id="__codelineno-22-53" name="__codelineno-22-53" href="#__codelineno-22-53"></a><span class="w"> </span><span class="n">res</span><span class="p">[(</span><span class="o">*</span><span class="n">index</span><span class="p">)</span><span class="o">++</span><span class="p">]</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">abt</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-54" name="__codelineno-22-54" href="#__codelineno-22-54"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </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><span class="w"> </span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="n">index</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-55" name="__codelineno-22-55" href="#__codelineno-22-55"></a><span class="w"> </span><span class="c1">// 后序遍历</span>
|
||||
<a id="__codelineno-22-56" name="__codelineno-22-56" href="#__codelineno-22-56"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">strcmp</span><span class="p">(</span><span class="n">order</span><span class="p">,</span><span class="w"> </span><span class="s">"post"</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span>
|
||||
<a id="__codelineno-22-57" name="__codelineno-22-57" href="#__codelineno-22-57"></a><span class="w"> </span><span class="n">res</span><span class="p">[(</span><span class="o">*</span><span class="n">index</span><span class="p">)</span><span class="o">++</span><span class="p">]</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">abt</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-58" name="__codelineno-22-58" href="#__codelineno-22-58"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-59" name="__codelineno-22-59" href="#__codelineno-22-59"></a>
|
||||
<a id="__codelineno-22-60" name="__codelineno-22-60" href="#__codelineno-22-60"></a><span class="cm">/* 前序遍历 */</span>
|
||||
<a id="__codelineno-22-61" name="__codelineno-22-61" href="#__codelineno-22-61"></a><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="nf">preOrder</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-62" name="__codelineno-22-62" href="#__codelineno-22-62"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">abt</span><span class="p">));</span>
|
||||
<a id="__codelineno-22-63" name="__codelineno-22-63" href="#__codelineno-22-63"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-64" name="__codelineno-22-64" href="#__codelineno-22-64"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="s">"pre"</span><span class="p">,</span><span class="w"> </span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">index</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-65" name="__codelineno-22-65" href="#__codelineno-22-65"></a><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">index</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-66" name="__codelineno-22-66" href="#__codelineno-22-66"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">res</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-67" name="__codelineno-22-67" href="#__codelineno-22-67"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-68" name="__codelineno-22-68" href="#__codelineno-22-68"></a>
|
||||
<a id="__codelineno-22-69" name="__codelineno-22-69" href="#__codelineno-22-69"></a><span class="cm">/* 中序遍历 */</span>
|
||||
<a id="__codelineno-22-70" name="__codelineno-22-70" href="#__codelineno-22-70"></a><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="nf">inOrder</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-71" name="__codelineno-22-71" href="#__codelineno-22-71"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">abt</span><span class="p">));</span>
|
||||
<a id="__codelineno-22-72" name="__codelineno-22-72" href="#__codelineno-22-72"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-73" name="__codelineno-22-73" href="#__codelineno-22-73"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="s">"in"</span><span class="p">,</span><span class="w"> </span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">index</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-74" name="__codelineno-22-74" href="#__codelineno-22-74"></a><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">index</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-75" name="__codelineno-22-75" href="#__codelineno-22-75"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">res</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-76" name="__codelineno-22-76" href="#__codelineno-22-76"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-77" name="__codelineno-22-77" href="#__codelineno-22-77"></a>
|
||||
<a id="__codelineno-22-78" name="__codelineno-22-78" href="#__codelineno-22-78"></a><span class="cm">/* 后序遍历 */</span>
|
||||
<a id="__codelineno-22-79" name="__codelineno-22-79" href="#__codelineno-22-79"></a><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="nf">postOrder</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-80" name="__codelineno-22-80" href="#__codelineno-22-80"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">abt</span><span class="p">));</span>
|
||||
<a id="__codelineno-22-81" name="__codelineno-22-81" href="#__codelineno-22-81"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-82" name="__codelineno-22-82" href="#__codelineno-22-82"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="s">"post"</span><span class="p">,</span><span class="w"> </span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">index</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-83" name="__codelineno-22-83" href="#__codelineno-22-83"></a><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">index</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-84" name="__codelineno-22-84" href="#__codelineno-22-84"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">res</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-85" name="__codelineno-22-85" href="#__codelineno-22-85"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-16" name="__codelineno-22-16" href="#__codelineno-22-16"></a><span class="cm">/* 析构函数 */</span>
|
||||
<a id="__codelineno-22-17" name="__codelineno-22-17" href="#__codelineno-22-17"></a><span class="kt">void</span><span class="w"> </span><span class="nf">delArrayBinaryTree</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-18" name="__codelineno-22-18" href="#__codelineno-22-18"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">abt</span><span class="o">-></span><span class="n">tree</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-19" name="__codelineno-22-19" href="#__codelineno-22-19"></a><span class="w"> </span><span class="n">free</span><span class="p">(</span><span class="n">abt</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-20" name="__codelineno-22-20" href="#__codelineno-22-20"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-21" name="__codelineno-22-21" href="#__codelineno-22-21"></a>
|
||||
<a id="__codelineno-22-22" name="__codelineno-22-22" href="#__codelineno-22-22"></a><span class="cm">/* 节点数量 */</span>
|
||||
<a id="__codelineno-22-23" name="__codelineno-22-23" href="#__codelineno-22-23"></a><span class="kt">int</span><span class="w"> </span><span class="nf">size</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-24" name="__codelineno-22-24" href="#__codelineno-22-24"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">abt</span><span class="o">-></span><span class="n">size</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-25" name="__codelineno-22-25" href="#__codelineno-22-25"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-26" name="__codelineno-22-26" href="#__codelineno-22-26"></a>
|
||||
<a id="__codelineno-22-27" name="__codelineno-22-27" href="#__codelineno-22-27"></a><span class="cm">/* 获取索引为 i 节点的值 */</span>
|
||||
<a id="__codelineno-22-28" name="__codelineno-22-28" href="#__codelineno-22-28"></a><span class="kt">int</span><span class="w"> </span><span class="nf">val</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-29" name="__codelineno-22-29" href="#__codelineno-22-29"></a><span class="w"> </span><span class="c1">// 若索引越界,则返回 INT_MAX ,代表空位</span>
|
||||
<a id="__codelineno-22-30" name="__codelineno-22-30" href="#__codelineno-22-30"></a><span class="w"> </span><span class="k">if</span><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">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><span class="p">(</span><span class="n">abt</span><span class="p">))</span>
|
||||
<a id="__codelineno-22-31" name="__codelineno-22-31" href="#__codelineno-22-31"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">INT_MAX</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-32" name="__codelineno-22-32" href="#__codelineno-22-32"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">abt</span><span class="o">-></span><span class="n">tree</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
|
||||
<a id="__codelineno-22-33" name="__codelineno-22-33" href="#__codelineno-22-33"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-34" name="__codelineno-22-34" href="#__codelineno-22-34"></a>
|
||||
<a id="__codelineno-22-35" name="__codelineno-22-35" href="#__codelineno-22-35"></a><span class="cm">/* 层序遍历 */</span>
|
||||
<a id="__codelineno-22-36" name="__codelineno-22-36" href="#__codelineno-22-36"></a><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="nf">levelOrder</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-37" name="__codelineno-22-37" href="#__codelineno-22-37"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">abt</span><span class="p">));</span>
|
||||
<a id="__codelineno-22-38" name="__codelineno-22-38" href="#__codelineno-22-38"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-39" name="__codelineno-22-39" href="#__codelineno-22-39"></a><span class="w"> </span><span class="c1">// 直接遍历数组</span>
|
||||
<a id="__codelineno-22-40" name="__codelineno-22-40" href="#__codelineno-22-40"></a><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</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="p">;</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><span class="p">(</span><span class="n">abt</span><span class="p">);</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-41" name="__codelineno-22-41" href="#__codelineno-22-41"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">val</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="n">INT_MAX</span><span class="p">)</span>
|
||||
<a id="__codelineno-22-42" name="__codelineno-22-42" href="#__codelineno-22-42"></a><span class="w"> </span><span class="n">res</span><span class="p">[</span><span class="n">index</span><span class="o">++</span><span class="p">]</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">abt</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-43" name="__codelineno-22-43" href="#__codelineno-22-43"></a><span class="w"> </span><span class="p">}</span>
|
||||
<a id="__codelineno-22-44" name="__codelineno-22-44" href="#__codelineno-22-44"></a><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">index</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-45" name="__codelineno-22-45" href="#__codelineno-22-45"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">res</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-46" name="__codelineno-22-46" href="#__codelineno-22-46"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-47" name="__codelineno-22-47" href="#__codelineno-22-47"></a>
|
||||
<a id="__codelineno-22-48" name="__codelineno-22-48" href="#__codelineno-22-48"></a><span class="cm">/* 深度优先遍历 */</span>
|
||||
<a id="__codelineno-22-49" name="__codelineno-22-49" href="#__codelineno-22-49"></a><span class="kt">void</span><span class="w"> </span><span class="nf">dfs</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">order</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">index</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-50" name="__codelineno-22-50" href="#__codelineno-22-50"></a><span class="w"> </span><span class="c1">// 若为空位,则返回</span>
|
||||
<a id="__codelineno-22-51" name="__codelineno-22-51" href="#__codelineno-22-51"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">val</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">INT_MAX</span><span class="p">)</span>
|
||||
<a id="__codelineno-22-52" name="__codelineno-22-52" href="#__codelineno-22-52"></a><span class="w"> </span><span class="k">return</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-53" name="__codelineno-22-53" href="#__codelineno-22-53"></a><span class="w"> </span><span class="c1">// 前序遍历</span>
|
||||
<a id="__codelineno-22-54" name="__codelineno-22-54" href="#__codelineno-22-54"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">strcmp</span><span class="p">(</span><span class="n">order</span><span class="p">,</span><span class="w"> </span><span class="s">"pre"</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span>
|
||||
<a id="__codelineno-22-55" name="__codelineno-22-55" href="#__codelineno-22-55"></a><span class="w"> </span><span class="n">res</span><span class="p">[(</span><span class="o">*</span><span class="n">index</span><span class="p">)</span><span class="o">++</span><span class="p">]</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">abt</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-56" name="__codelineno-22-56" href="#__codelineno-22-56"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </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><span class="w"> </span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="n">index</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-57" name="__codelineno-22-57" href="#__codelineno-22-57"></a><span class="w"> </span><span class="c1">// 中序遍历</span>
|
||||
<a id="__codelineno-22-58" name="__codelineno-22-58" href="#__codelineno-22-58"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">strcmp</span><span class="p">(</span><span class="n">order</span><span class="p">,</span><span class="w"> </span><span class="s">"in"</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span>
|
||||
<a id="__codelineno-22-59" name="__codelineno-22-59" href="#__codelineno-22-59"></a><span class="w"> </span><span class="n">res</span><span class="p">[(</span><span class="o">*</span><span class="n">index</span><span class="p">)</span><span class="o">++</span><span class="p">]</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">abt</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-60" name="__codelineno-22-60" href="#__codelineno-22-60"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </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><span class="w"> </span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="n">index</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-61" name="__codelineno-22-61" href="#__codelineno-22-61"></a><span class="w"> </span><span class="c1">// 后序遍历</span>
|
||||
<a id="__codelineno-22-62" name="__codelineno-22-62" href="#__codelineno-22-62"></a><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">strcmp</span><span class="p">(</span><span class="n">order</span><span class="p">,</span><span class="w"> </span><span class="s">"post"</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span>
|
||||
<a id="__codelineno-22-63" name="__codelineno-22-63" href="#__codelineno-22-63"></a><span class="w"> </span><span class="n">res</span><span class="p">[(</span><span class="o">*</span><span class="n">index</span><span class="p">)</span><span class="o">++</span><span class="p">]</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">abt</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-64" name="__codelineno-22-64" href="#__codelineno-22-64"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-65" name="__codelineno-22-65" href="#__codelineno-22-65"></a>
|
||||
<a id="__codelineno-22-66" name="__codelineno-22-66" href="#__codelineno-22-66"></a><span class="cm">/* 前序遍历 */</span>
|
||||
<a id="__codelineno-22-67" name="__codelineno-22-67" href="#__codelineno-22-67"></a><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="nf">preOrder</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-68" name="__codelineno-22-68" href="#__codelineno-22-68"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">abt</span><span class="p">));</span>
|
||||
<a id="__codelineno-22-69" name="__codelineno-22-69" href="#__codelineno-22-69"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-70" name="__codelineno-22-70" href="#__codelineno-22-70"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="s">"pre"</span><span class="p">,</span><span class="w"> </span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">index</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-71" name="__codelineno-22-71" href="#__codelineno-22-71"></a><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">index</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-72" name="__codelineno-22-72" href="#__codelineno-22-72"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">res</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-73" name="__codelineno-22-73" href="#__codelineno-22-73"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-74" name="__codelineno-22-74" href="#__codelineno-22-74"></a>
|
||||
<a id="__codelineno-22-75" name="__codelineno-22-75" href="#__codelineno-22-75"></a><span class="cm">/* 中序遍历 */</span>
|
||||
<a id="__codelineno-22-76" name="__codelineno-22-76" href="#__codelineno-22-76"></a><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="nf">inOrder</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-77" name="__codelineno-22-77" href="#__codelineno-22-77"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">abt</span><span class="p">));</span>
|
||||
<a id="__codelineno-22-78" name="__codelineno-22-78" href="#__codelineno-22-78"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-79" name="__codelineno-22-79" href="#__codelineno-22-79"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="s">"in"</span><span class="p">,</span><span class="w"> </span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">index</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-80" name="__codelineno-22-80" href="#__codelineno-22-80"></a><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">index</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-81" name="__codelineno-22-81" href="#__codelineno-22-81"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">res</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-82" name="__codelineno-22-82" href="#__codelineno-22-82"></a><span class="p">}</span>
|
||||
<a id="__codelineno-22-83" name="__codelineno-22-83" href="#__codelineno-22-83"></a>
|
||||
<a id="__codelineno-22-84" name="__codelineno-22-84" href="#__codelineno-22-84"></a><span class="cm">/* 后序遍历 */</span>
|
||||
<a id="__codelineno-22-85" name="__codelineno-22-85" href="#__codelineno-22-85"></a><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="nf">postOrder</span><span class="p">(</span><span class="n">ArrayBinaryTree</span><span class="w"> </span><span class="o">*</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||||
<a id="__codelineno-22-86" name="__codelineno-22-86" href="#__codelineno-22-86"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">size</span><span class="p">(</span><span class="n">abt</span><span class="p">));</span>
|
||||
<a id="__codelineno-22-87" name="__codelineno-22-87" href="#__codelineno-22-87"></a><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-88" name="__codelineno-22-88" href="#__codelineno-22-88"></a><span class="w"> </span><span class="n">dfs</span><span class="p">(</span><span class="n">abt</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="s">"post"</span><span class="p">,</span><span class="w"> </span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">index</span><span class="p">);</span>
|
||||
<a id="__codelineno-22-89" name="__codelineno-22-89" href="#__codelineno-22-89"></a><span class="w"> </span><span class="o">*</span><span class="n">returnSize</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">index</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-90" name="__codelineno-22-90" href="#__codelineno-22-90"></a><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">res</span><span class="p">;</span>
|
||||
<a id="__codelineno-22-91" name="__codelineno-22-91" href="#__codelineno-22-91"></a><span class="p">}</span>
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="tabbed-block">
|
||||
|
|
File diff suppressed because one or more lines are too long
206
sitemap.xml
206
sitemap.xml
|
@ -2,517 +2,517 @@
|
|||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_appendix/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_appendix/contribution/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_appendix/installation/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_appendix/terminology/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/array/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/linked_list/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/list/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_array_and_linkedlist/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/backtracking_algorithm/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/n_queens_problem/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/permutations_problem/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/subset_sum_problem/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_backtracking/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/iteration_and_recursion/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/performance_evaluation/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/space_complexity/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_computational_complexity/time_complexity/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/basic_data_types/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/character_encoding/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/classification_of_data_structure/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/number_encoding/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_data_structure/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/binary_search_recur/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/build_binary_tree_problem/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/divide_and_conquer/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/hanota_problem/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_divide_and_conquer/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/dp_problem_features/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/dp_solution_pipeline/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/edit_distance_problem/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/intro_to_dynamic_programming/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/knapsack_problem/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_dynamic_programming/unbounded_knapsack_problem/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/graph/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/graph_operations/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/graph_traversal/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_graph/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/fractional_knapsack_problem/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/greedy_algorithm/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/max_capacity_problem/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/max_product_cutting_problem/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_greedy/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/hash_algorithm/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/hash_collision/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/hash_map/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_hashing/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/build_heap/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/heap/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_heap/top_k/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_introduction/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_introduction/algorithms_are_everywhere/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_introduction/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_introduction/what_is_dsa/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_preface/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_preface/about_the_book/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_preface/suggestions/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_preface/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_reference/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/binary_search/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/binary_search_edge/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/binary_search_insertion/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/replace_linear_by_hashing/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/searching_algorithm_revisited/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_searching/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/bubble_sort/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/bucket_sort/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/counting_sort/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/heap_sort/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/insertion_sort/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/merge_sort/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/quick_sort/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/radix_sort/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/selection_sort/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/sorting_algorithm/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_sorting/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/deque/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/queue/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/stack/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_stack_and_queue/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/array_representation_of_tree/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/avl_tree/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/binary_search_tree/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/binary_tree/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/binary_tree_traversal/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.hello-algo.com/chapter_tree/summary/</loc>
|
||||
<lastmod>2023-10-29</lastmod>
|
||||
<lastmod>2023-10-31</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
</urlset>
|
BIN
sitemap.xml.gz
BIN
sitemap.xml.gz
Binary file not shown.
Loading…
Reference in a new issue