From f42cec0f883e299eb2e84ffc52ae14ce8333b246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=96=E5=90=90=E7=AD=B7=E7=AD=B7?= <74196206+ztkuaikuai@users.noreply.github.com> Date: Sat, 17 May 2025 17:26:38 +0800 Subject: [PATCH] fix(graph): enhance the judgment of boundary conditions for removeEdge functions (#1412) --- 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'); }