From bc0e32af5746fd466e5c6c399c9a0b3b7d8c8240 Mon Sep 17 00:00:00 2001 From: ztkuaikuai <2647731903@qq.com> Date: Sun, 7 Jul 2024 18:40:23 +0800 Subject: [PATCH] fix(graph): enhance the judgment of boundary conditions for removeEdge functions --- codes/javascript/chapter_graph/graph_adjacency_list.js | 3 ++- codes/typescript/chapter_graph/graph_adjacency_list.ts | 3 ++- zh-hant/codes/javascript/chapter_graph/graph_adjacency_list.js | 3 ++- zh-hant/codes/typescript/chapter_graph/graph_adjacency_list.ts | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/codes/javascript/chapter_graph/graph_adjacency_list.js b/codes/javascript/chapter_graph/graph_adjacency_list.js index ec7567c3c..f3daaeb17 100644 --- a/codes/javascript/chapter_graph/graph_adjacency_list.js +++ b/codes/javascript/chapter_graph/graph_adjacency_list.js @@ -46,7 +46,8 @@ class GraphAdjList { if ( !this.adjList.has(vet1) || !this.adjList.has(vet2) || - vet1 === vet2 + vet1 === vet2 || + this.adjList.get(vet1).indexOf(vet2) === -1 ) { throw new Error('Illegal Argument Exception'); } diff --git a/codes/typescript/chapter_graph/graph_adjacency_list.ts b/codes/typescript/chapter_graph/graph_adjacency_list.ts index 4c7692312..c928e72e4 100644 --- a/codes/typescript/chapter_graph/graph_adjacency_list.ts +++ b/codes/typescript/chapter_graph/graph_adjacency_list.ts @@ -46,7 +46,8 @@ class GraphAdjList { if ( !this.adjList.has(vet1) || !this.adjList.has(vet2) || - vet1 === vet2 + vet1 === vet2 || + this.adjList.get(vet1).indexOf(vet2) === -1 ) { throw new Error('Illegal Argument Exception'); } diff --git a/zh-hant/codes/javascript/chapter_graph/graph_adjacency_list.js b/zh-hant/codes/javascript/chapter_graph/graph_adjacency_list.js index 6b7ff8c71..6e50bad47 100644 --- a/zh-hant/codes/javascript/chapter_graph/graph_adjacency_list.js +++ b/zh-hant/codes/javascript/chapter_graph/graph_adjacency_list.js @@ -46,7 +46,8 @@ class GraphAdjList { if ( !this.adjList.has(vet1) || !this.adjList.has(vet2) || - vet1 === vet2 + vet1 === vet2 || + this.adjList.get(vet1).indexOf(vet2) === -1 ) { throw new Error('Illegal Argument Exception'); } diff --git a/zh-hant/codes/typescript/chapter_graph/graph_adjacency_list.ts b/zh-hant/codes/typescript/chapter_graph/graph_adjacency_list.ts index 13c76a1e5..bd137fd84 100644 --- a/zh-hant/codes/typescript/chapter_graph/graph_adjacency_list.ts +++ b/zh-hant/codes/typescript/chapter_graph/graph_adjacency_list.ts @@ -46,7 +46,8 @@ class GraphAdjList { if ( !this.adjList.has(vet1) || !this.adjList.has(vet2) || - vet1 === vet2 + vet1 === vet2 || + this.adjList.get(vet1).indexOf(vet2) === -1 ) { throw new Error('Illegal Argument Exception'); }