diff --git a/codes/go/chapter_graph/graph_adjacency_list.go b/codes/go/chapter_graph/graph_adjacency_list.go index c3a94836c..dfec71d30 100644 --- a/codes/go/chapter_graph/graph_adjacency_list.go +++ b/codes/go/chapter_graph/graph_adjacency_list.go @@ -57,8 +57,8 @@ func (g *graphAdjList) removeEdge(vet1 Vertex, vet2 Vertex) { panic("error") } // 删除边 vet1 - vet2 - DeleteSliceElms(g.adjList[vet1], vet2) - DeleteSliceElms(g.adjList[vet2], vet1) + g.adjList[vet1] = DeleteSliceElms(g.adjList[vet1], vet2) + g.adjList[vet2] = DeleteSliceElms(g.adjList[vet2], vet1) } /* 添加顶点 */ @@ -80,8 +80,8 @@ func (g *graphAdjList) removeVertex(vet Vertex) { // 在邻接表中删除顶点 vet 对应的链表 delete(g.adjList, vet) // 遍历其他顶点的链表,删除所有包含 vet 的边 - for _, list := range g.adjList { - DeleteSliceElms(list, vet) + for v, list := range g.adjList { + g.adjList[v] = DeleteSliceElms(list, vet) } }