Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文本勘误【数据结构-图】 #22

Open
Shalomw opened this issue Dec 30, 2024 · 0 comments
Open

文本勘误【数据结构-图】 #22

Shalomw opened this issue Dec 30, 2024 · 0 comments

Comments

@Shalomw
Copy link

Shalomw commented Dec 30, 2024

  1. 感觉示例代码用的是邻接表法?文本写的是邻接矩阵
// 添加顶点
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)
}
  1. 代码里写的是 new Dictionary() ,但字典那章写的是 class Map ,感觉可以统一一下
class Graph {
  constructor() {
    this.vertexes = []; // 存储顶点
    this.adjList = new Dictionay(); //存储边信息
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant