From 02ca008341f72bed4c749776a4ccb69bd6211eac Mon Sep 17 00:00:00 2001 From: Spiros Maggioros Date: Sat, 20 Jan 2024 19:15:38 +0200 Subject: [PATCH] minor change for dfs/bfs minor change when element is not in graph when dfs/bfs-ing. --- src/classes/graph/graph.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/classes/graph/graph.h b/src/classes/graph/graph.h index ec12dfa4..c073a19d 100644 --- a/src/classes/graph/graph.h +++ b/src/classes/graph/graph.h @@ -89,7 +89,7 @@ template size_t graph::size(){return __elements.size();} template std::vector graph::dfs(T start) { std::vector path; - if(this -> empty()){ + if(this -> empty() || __elements.find(start) == __elements.end()){ return path; } std::stack s; @@ -112,7 +112,7 @@ template std::vector graph::dfs(T start) { template std::vector graph::bfs(T start) { std::vector path; - if(this -> empty()){ + if(this -> empty() || __elements.find(start) == __elements.end()){ return path; } std::queue q; @@ -400,7 +400,7 @@ template int64_t weighted_graph::shortest_path(T start, T end) { template std::vector weighted_graph::dfs(T start) { std::vector path; - if(this -> empty()){ + if(this -> empty() || __elements.find(start) == __elements.end()){ return path; } std::queue q; @@ -426,7 +426,7 @@ template std::vector weighted_graph::dfs(T start) { template std::vector weighted_graph::bfs(T start) { std::vector path; - if(this -> empty()){ + if(this -> empty() || __elements.find(start) == __elements.end()){ return path; } std::queue q;