2011年5月5日 星期四

[ Data Structures with Java ] Section 25.2 : Strongly Connected Components - Example 25.2


Preface :
The example outputs the strong components for the graph in below figure. Assume that g is the graph and componentList is the ArrayList of strong component lists returned by the method strongComponents().

Corresponding graph file :
- scc.dat :
7
A B C D E F G
8
A B 1
B C 1
C A 1
C E 1
E D 1
D G 1
G F 1
F D 1


- Example 25.2 :
  1. public static void example25_2(){  
  2.     JGraph g = JGraph.readGraph("scc.dat");  
  3.     ArrayList> componentList = new ArrayList>();  
  4.     JGraph.strongComponents(g, componentList);  
  5.     int scCount = 0;  
  6.     for(LinkedList component: componentList) {  
  7.         scCount++;  
  8.         System.out.println("Component "+scCount+": "+component);  
  9.     }  
  10. }  


Output :
Component 1: [A, C, B]
Component 2: [E]
Component 3: [D, F, G]

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...