From 763955aa8be11c0c78db2456069b688ac3cbbd6b Mon Sep 17 00:00:00 2001 From: Jerry You Date: Tue, 4 Jul 2023 21:08:32 +0800 Subject: [PATCH] fix: removeEdge not effects on graph in golang (#503) * fix(graph/adjacency_list):removeEdge not effects on graph in golang * remove unecessary package right now * Delete go.sum --------- Co-authored-by: Yudong Jin --- codes/go/chapter_graph/graph_adjacency_list.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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) } }