-
Notifications
You must be signed in to change notification settings - Fork 287
Open
@Shalomw
Description
- 感觉示例代码用的是邻接表法?文本写的是邻接矩阵
// 添加顶点 addVertex(val) { // 添加点 this.vertexes.push(val) // 添加点的关系 采用邻接矩阵法 结构用 Map this.adjList.set(val, []) } // 添加边 addEdge(val1, val2) { // 添加边需要传入两个顶点,因为边是两个顶点之间的边,边不可能单独存在。 // 这里实现的是无向图,所以这里不考虑方向问题 this.adjList.get(val1).push(val2) this.adjList.get(val2).push(val1) }
- 代码里写的是
new Dictionary()
,但字典那章写的是class Map
,感觉可以统一一下
class Graph { constructor() { this.vertexes = []; // 存储顶点 this.adjList = new Dictionay(); //存储边信息 } }
Metadata
Metadata
Assignees
Labels
No labels