Skip to content

Commit

Permalink
minor change for dfs/bfs
Browse files Browse the repository at this point in the history
minor change when element is not in graph when dfs/bfs-ing.
  • Loading branch information
spirosmaggioros committed Jan 20, 2024
1 parent 9a87090 commit 02ca008
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/classes/graph/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ template<typename T> size_t graph<T>::size(){return __elements.size();}

template <typename T> std::vector<T> graph<T>::dfs(T start) {
std::vector<T> path;
if(this -> empty()){
if(this -> empty() || __elements.find(start) == __elements.end()){
return path;
}
std::stack<T> s;
Expand All @@ -112,7 +112,7 @@ template <typename T> std::vector<T> graph<T>::dfs(T start) {

template <typename T> std::vector<T> graph<T>::bfs(T start) {
std::vector<T> path;
if(this -> empty()){
if(this -> empty() || __elements.find(start) == __elements.end()){
return path;
}
std::queue<T> q;
Expand Down Expand Up @@ -400,7 +400,7 @@ template <typename T> int64_t weighted_graph<T>::shortest_path(T start, T end) {
template <typename T> std::vector<T> weighted_graph<T>::dfs(T start) {

std::vector<T> path;
if(this -> empty()){
if(this -> empty() || __elements.find(start) == __elements.end()){
return path;
}
std::queue<T> q;
Expand All @@ -426,7 +426,7 @@ template <typename T> std::vector<T> weighted_graph<T>::dfs(T start) {

template <typename T> std::vector<T> weighted_graph<T>::bfs(T start) {
std::vector<T> path;
if(this -> empty()){
if(this -> empty() || __elements.find(start) == __elements.end()){
return path;
}
std::queue<T> q;
Expand Down

0 comments on commit 02ca008

Please sign in to comment.