## 2015年10月31日 星期六

### [ Java 代碼範本 ] JGraphT - Bread First Search

Introduction

Sample Code

1. package lab;
2.
3. import static org.junit.Assert.*
4.
5. import org.jgraph.graph.DefaultEdge
6. import org.jgrapht.UndirectedGraph
7. import org.jgrapht.graph.SimpleGraph
9. import org.jgrapht.traverse.DepthFirstIterator
10. import org.jgrapht.traverse.GraphIterator
11.
12. UndirectedGraph graph =
13.         new SimpleGraph (DefaultEdge.class);
14.
15.
16. // Graph
17. // 1-----2-------+
18. //   |           |
19. //   +---5---3---+---4
20. //       |           |
21. //       +-----------+
22.
23. 5.times{
25. }
26.
27. def edges = [:]
28. edges[1]=[2,5]
29. edges[2]=[3,4]
30. edges[3]=[5,4]
31. edges[4]=[5]
32.
33. edges.each{ k, v->
34.     v.each{
36.     }
37. }
38.
39. iterator =
41. while (iterator.hasNext()) {
42. System.out.printf("%d ", iterator.next());
43. }
44. println()

1 2 5 3 4

Supplement
JGraphT - Depth First Search
Coursera - Algorithms, Part II - Breadth First Search
[ Intro Alg ] Elementary Graph Algorithms - Breadth-ﬁrst search
[ 資料結構 小學堂 ] 圖形結構 : 圖形的追蹤 - 先廣後深法 (BFS)
[ 資料結構 小學堂 ] 佇列 : 認識佇列

### [LeetCode] Medium - 1043. Partition Array for Maximum Sum

Source From  Here Question Given an integer array  A , you partition the array into ( contiguous ) subarrays of length at most  K . After ...