小编jav*_*b37的帖子

无向图的邻接表

任何人都知道在哪里可以获得使用邻接列表来表示无向图的通用示例代码?

图形数据来自.txt文件:节点在第一行指定,用空格分隔.边缘在以下行中指定,每个边缘在单独的行上.

像这样...

1 2 3 4 5 6 7 8 9

1 2

1 4

1 3

2 4

2 5

3 6

4 6

5 7

5 8

6 9

7 9

8 9
Run Code Online (Sandbox Code Playgroud)

我的.txt文件没有与图表方法连接.我也收到以下NPE错误:

Error: java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)

创建邻接列表并为无向图执行标准Graph ADT方法.

//TON of imports up here (removed for now)

class Graph<V> implements GraphADT1 <V>{

// Map of adjacency lists for each node
private HashMap<Integer, LinkedList<Integer>> adj;
private ArrayList<V> vertices;
private HashMap<V, LinkedHashSet<V>> neighbors;
private HashMap<V, Set<V>> neighborsView; 
private int edgeCount; …
Run Code Online (Sandbox Code Playgroud)

java graph adjacency-list

-2
推荐指数
1
解决办法
3万
查看次数

标签 统计

adjacency-list ×1

graph ×1

java ×1