⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 componentsdfs-cc.html

📁 经典的数据结构源代码(java 实现)
💻 HTML
字号:
<html><head><title>Code Fragment</title></head><body text=#000000><center></center><br><br><dl><dd><pre><font color = #ff0080>/** This class extends DFS to compute the connected components of a graph. */</font><font color=#8000a0>public</font> <font color=#8000a0><font color=#ff8000>class</font> </font>ComponentsDFS&lt;V, E&gt; <font color=#8000a0><font color=#ff8000>extends</font> </font>DFS&lt;V, E, Object, Integer&gt; {  <font color=#8000a0><font color=#8000a0>protected</font> </font>Integer compNumber; <font color=#ff0080>// Connected component number</font>  <font color=#8000a0><font color=#8000a0>protected</font> </font>Object COMPONENT = <font color=#8000a0><font color=#ff8000>new</font> </font><font color=#0000ff>Object</font>(); <font color=#ff0080>// Connected comp. selector</font>  <font color=#8000a0><font color=#8000a0>protected</font> </font><font color=#8000a0>void</font> <font color=#0000ff>setup</font>() { compNumber = 1; }  <font color=#8000a0><font color=#8000a0>protected</font> </font><font color=#8000a0>void</font> <font color=#0000ff>startVisit</font>(Vertex&lt;V&gt; v) { v.<font color=#0000ff>put</font>(COMPONENT, compNumber);}  <font color=#8000a0><font color=#8000a0>protected</font> </font>Integer <font color=#0000ff>finalResult</font>(Integer dfsResult) {     <font color=#ff8000>for</font><font color=#0000ff> </font>(Vertex&lt;V&gt; v : graph.<font color=#0000ff>vertices</font>()) <font color=#ff0080>// check for any unvisited vertices</font>      <font color=#ff8000>if</font><font color=#0000ff> </font>(v.<font color=#0000ff>get</font>(STATUS) == UNVISITED) {         compNumber += 1;  <font color=#ff0080>// we have found another connected component</font>	<font color=#0000ff>dfsTraversal</font>(v);  <font color=#ff0080>// visit all the vertices of this component</font>      }    <font color=#8000a0><font color=#ff8000>return</font> </font>compNumber;  }}</dl></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -