mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 14:26:29 +08:00
deploy
This commit is contained in:
parent
c2b291aa5f
commit
6fce2aa052
5 changed files with 8 additions and 9 deletions
BIN
.DS_Store
vendored
Normal file
BIN
.DS_Store
vendored
Normal file
Binary file not shown.
|
@ -2202,13 +2202,12 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p>基于邻接表实现图的代码如下所示。</p>
|
<p>基于邻接表实现图的代码如下所示。细心的同学可能注意到,<strong>我们在邻接表中使用 <code>Vertex</code> 结点类来表示顶点</strong>,这样做的原因是:</p>
|
||||||
<div class="admonition question">
|
<ul>
|
||||||
<p class="admonition-title">为什么需要使用顶点类 <code>Vertex</code> ?</p>
|
<li>如果我们选择通过顶点值来区分不同顶点,那么值重复的顶点将无法被区分。</li>
|
||||||
<p>如果我们直接通过顶点值来区分不同顶点,那么值重复的顶点将无法被区分。
|
<li>如果类似邻接矩阵那样,使用顶点列表索引来区分不同顶点。那么,假设我们想要删除索引为 <span class="arithmatex">\(i\)</span> 的顶点,则需要遍历整个邻接表,将其中 <span class="arithmatex">\(> i\)</span> 的索引全部执行 <span class="arithmatex">\(-1\)</span> ,这样操作效率太低。</li>
|
||||||
如果建立一个顶点列表,用索引来区分不同顶点,那么假设我们想要删除索引为 <code>i</code> 的顶点,则需要遍历整个邻接表,将其中 <span class="arithmatex">\(> i\)</span> 的索引全部执行 <span class="arithmatex">\(-1\)</span> ,这样的操作是比较耗时的。
|
<li>因此我们考虑引入顶点类 <code>Vertex</code> ,使得每个顶点都是唯一的对象,此时删除顶点时就无需改动其余顶点了。</li>
|
||||||
因此,通过引入顶点类 <code>Vertex</code> ,每个顶点都是唯一的对象,这样在删除操作时就无需改动其余顶点了。</p>
|
</ul>
|
||||||
</div>
|
|
||||||
<div class="tabbed-set tabbed-alternate" data-tabs="4:10"><input checked="checked" id="__tabbed_4_1" name="__tabbed_4" type="radio" /><input id="__tabbed_4_2" name="__tabbed_4" type="radio" /><input id="__tabbed_4_3" name="__tabbed_4" type="radio" /><input id="__tabbed_4_4" name="__tabbed_4" type="radio" /><input id="__tabbed_4_5" name="__tabbed_4" type="radio" /><input id="__tabbed_4_6" name="__tabbed_4" type="radio" /><input id="__tabbed_4_7" name="__tabbed_4" type="radio" /><input id="__tabbed_4_8" name="__tabbed_4" type="radio" /><input id="__tabbed_4_9" name="__tabbed_4" type="radio" /><input id="__tabbed_4_10" name="__tabbed_4" type="radio" /><div class="tabbed-labels"><label for="__tabbed_4_1">Java</label><label for="__tabbed_4_2">C++</label><label for="__tabbed_4_3">Python</label><label for="__tabbed_4_4">Go</label><label for="__tabbed_4_5">JavaScript</label><label for="__tabbed_4_6">TypeScript</label><label for="__tabbed_4_7">C</label><label for="__tabbed_4_8">C#</label><label for="__tabbed_4_9">Swift</label><label for="__tabbed_4_10">Zig</label></div>
|
<div class="tabbed-set tabbed-alternate" data-tabs="4:10"><input checked="checked" id="__tabbed_4_1" name="__tabbed_4" type="radio" /><input id="__tabbed_4_2" name="__tabbed_4" type="radio" /><input id="__tabbed_4_3" name="__tabbed_4" type="radio" /><input id="__tabbed_4_4" name="__tabbed_4" type="radio" /><input id="__tabbed_4_5" name="__tabbed_4" type="radio" /><input id="__tabbed_4_6" name="__tabbed_4" type="radio" /><input id="__tabbed_4_7" name="__tabbed_4" type="radio" /><input id="__tabbed_4_8" name="__tabbed_4" type="radio" /><input id="__tabbed_4_9" name="__tabbed_4" type="radio" /><input id="__tabbed_4_10" name="__tabbed_4" type="radio" /><div class="tabbed-labels"><label for="__tabbed_4_1">Java</label><label for="__tabbed_4_2">C++</label><label for="__tabbed_4_3">Python</label><label for="__tabbed_4_4">Go</label><label for="__tabbed_4_5">JavaScript</label><label for="__tabbed_4_6">TypeScript</label><label for="__tabbed_4_7">C</label><label for="__tabbed_4_8">C#</label><label for="__tabbed_4_9">Swift</label><label for="__tabbed_4_10">Zig</label></div>
|
||||||
<div class="tabbed-content">
|
<div class="tabbed-content">
|
||||||
<div class="tabbed-block">
|
<div class="tabbed-block">
|
||||||
|
|
|
@ -1666,7 +1666,7 @@
|
||||||
<ol>
|
<ol>
|
||||||
<li>将遍历起始顶点 <code>startVet</code> 加入队列,并开启循环;</li>
|
<li>将遍历起始顶点 <code>startVet</code> 加入队列,并开启循环;</li>
|
||||||
<li>在循环的每轮迭代中,弹出队首顶点弹出并记录访问,并将该顶点的所有邻接顶点加入到队列尾部;</li>
|
<li>在循环的每轮迭代中,弹出队首顶点弹出并记录访问,并将该顶点的所有邻接顶点加入到队列尾部;</li>
|
||||||
<li>循环 <code>2.</code> ,直到所有顶点访问完成后结束。</li>
|
<li>循环 <code>2.</code> ,直到所有顶点访问完成后结束;</li>
|
||||||
</ol>
|
</ol>
|
||||||
<p>为了防止重复遍历顶点,我们需要借助一个哈希表 <code>visited</code> 来记录哪些结点已被访问。</p>
|
<p>为了防止重复遍历顶点,我们需要借助一个哈希表 <code>visited</code> 来记录哪些结点已被访问。</p>
|
||||||
<div class="tabbed-set tabbed-alternate" data-tabs="1:10"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><input id="__tabbed_1_6" name="__tabbed_1" type="radio" /><input id="__tabbed_1_7" name="__tabbed_1" type="radio" /><input id="__tabbed_1_8" name="__tabbed_1" type="radio" /><input id="__tabbed_1_9" name="__tabbed_1" type="radio" /><input id="__tabbed_1_10" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Java</label><label for="__tabbed_1_2">C++</label><label for="__tabbed_1_3">Python</label><label for="__tabbed_1_4">Go</label><label for="__tabbed_1_5">JavaScript</label><label for="__tabbed_1_6">TypeScript</label><label for="__tabbed_1_7">C</label><label for="__tabbed_1_8">C#</label><label for="__tabbed_1_9">Swift</label><label for="__tabbed_1_10">Zig</label></div>
|
<div class="tabbed-set tabbed-alternate" data-tabs="1:10"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><input id="__tabbed_1_6" name="__tabbed_1" type="radio" /><input id="__tabbed_1_7" name="__tabbed_1" type="radio" /><input id="__tabbed_1_8" name="__tabbed_1" type="radio" /><input id="__tabbed_1_9" name="__tabbed_1" type="radio" /><input id="__tabbed_1_10" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Java</label><label for="__tabbed_1_2">C++</label><label for="__tabbed_1_3">Python</label><label for="__tabbed_1_4">Go</label><label for="__tabbed_1_5">JavaScript</label><label for="__tabbed_1_6">TypeScript</label><label for="__tabbed_1_7">C</label><label for="__tabbed_1_8">C#</label><label for="__tabbed_1_9">Swift</label><label for="__tabbed_1_10">Zig</label></div>
|
||||||
|
|
File diff suppressed because one or more lines are too long
BIN
sitemap.xml.gz
BIN
sitemap.xml.gz
Binary file not shown.
Loading…
Reference in a new issue