mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-30 05:43:10 +08:00
build
This commit is contained in:
@ -1103,8 +1103,8 @@ Below is the implementation code for graphs represented using an adjacency matri
|
||||
if (i < 0 || j < 0 || i >= size() || j >= size() || i == j)
|
||||
throw IndexOutOfBoundsException()
|
||||
// 在无向图中,邻接矩阵关于主对角线对称,即满足 (i, j) == (j, i)
|
||||
adjMat[i][j] = 1;
|
||||
adjMat[j][i] = 1;
|
||||
adjMat[i][j] = 1
|
||||
adjMat[j][i] = 1
|
||||
}
|
||||
|
||||
/* 删除边 */
|
||||
@ -1113,15 +1113,15 @@ Below is the implementation code for graphs represented using an adjacency matri
|
||||
// 索引越界与相等处理
|
||||
if (i < 0 || j < 0 || i >= size() || j >= size() || i == j)
|
||||
throw IndexOutOfBoundsException()
|
||||
adjMat[i][j] = 0;
|
||||
adjMat[j][i] = 0;
|
||||
adjMat[i][j] = 0
|
||||
adjMat[j][i] = 0
|
||||
}
|
||||
|
||||
/* 打印邻接矩阵 */
|
||||
fun print() {
|
||||
print("顶点列表 = ")
|
||||
println(vertices);
|
||||
println("邻接矩阵 =");
|
||||
println(vertices)
|
||||
println("邻接矩阵 =")
|
||||
printMatrix(adjMat)
|
||||
}
|
||||
}
|
||||
@ -2167,9 +2167,9 @@ Additionally, we use the `Vertex` class to represent vertices in the adjacency l
|
||||
init {
|
||||
// 添加所有顶点和边
|
||||
for (edge in edges) {
|
||||
addVertex(edge[0]!!);
|
||||
addVertex(edge[1]!!);
|
||||
addEdge(edge[0]!!, edge[1]!!);
|
||||
addVertex(edge[0]!!)
|
||||
addVertex(edge[1]!!)
|
||||
addEdge(edge[0]!!, edge[1]!!)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2184,7 +2184,7 @@ Additionally, we use the `Vertex` class to represent vertices in the adjacency l
|
||||
throw IllegalArgumentException()
|
||||
// 添加边 vet1 - vet2
|
||||
adjList[vet1]?.add(vet2)
|
||||
adjList[vet2]?.add(vet1);
|
||||
adjList[vet2]?.add(vet1)
|
||||
}
|
||||
|
||||
/* 删除边 */
|
||||
@ -2192,8 +2192,8 @@ Additionally, we use the `Vertex` class to represent vertices in the adjacency l
|
||||
if (!adjList.containsKey(vet1) || !adjList.containsKey(vet2) || vet1 == vet2)
|
||||
throw IllegalArgumentException()
|
||||
// 删除边 vet1 - vet2
|
||||
adjList[vet1]?.remove(vet2);
|
||||
adjList[vet2]?.remove(vet1);
|
||||
adjList[vet1]?.remove(vet2)
|
||||
adjList[vet2]?.remove(vet1)
|
||||
}
|
||||
|
||||
/* 添加顶点 */
|
||||
@ -2209,7 +2209,7 @@ Additionally, we use the `Vertex` class to represent vertices in the adjacency l
|
||||
if (!adjList.containsKey(vet))
|
||||
throw IllegalArgumentException()
|
||||
// 在邻接表中删除顶点 vet 对应的链表
|
||||
adjList.remove(vet);
|
||||
adjList.remove(vet)
|
||||
// 遍历其他顶点的链表,删除所有包含 vet 的边
|
||||
for (list in adjList.values) {
|
||||
list.remove(vet)
|
||||
|
Reference in New Issue
Block a user