From e7ad82411623d4dc388872dd8ed9d0301e3846e0 Mon Sep 17 00:00:00 2001 From: stefiosif Date: Tue, 12 Jul 2022 14:41:18 +0300 Subject: [PATCH] Put root of BFS tree as constructor parameter --- algorithm/{bfs.h => breadth_first_search.h} | 20 +++++++++----------- tree/breadth_first_tree.h | 9 ++++----- 2 files changed, 13 insertions(+), 16 deletions(-) rename algorithm/{bfs.h => breadth_first_search.h} (65%) diff --git a/algorithm/bfs.h b/algorithm/breadth_first_search.h similarity index 65% rename from algorithm/bfs.h rename to algorithm/breadth_first_search.h index c0de6ff..8bdb4b5 100644 --- a/algorithm/bfs.h +++ b/algorithm/breadth_first_search.h @@ -1,5 +1,5 @@ -#ifndef BFS_H_ -#define BFS_H_ +#ifndef BREADTH_FIRST_SEARCH_H_ +#define BREADTH_FIRST_SEARCH_H_ #include "graph/digraph.h" @@ -10,24 +10,22 @@ using namespace graph; namespace algo { template -class BFS { +class BreadthFirstSearch { public: - BFS() = default; + BreadthFirstSearch() = default; - BFS(Digraph G) : G(G) {} + BreadthFirstSearch(Digraph G) : G(G) {} - // - std::map> run(const T& root); + std::map> execute(const T& root); - // Initialize the lookup table that is used to - // show which vertices have been traversed + // Initialize LU table that show which vertices have been traversed std::map initExplore(); private: Graph G; }; template -std::map BFS::initExplore() { +std::map BreadthFirstSearch::initExplore() { std::map graphExplore; for (const auto& v : G.vertices) { graphExplore[v] = false; @@ -36,7 +34,7 @@ std::map BFS::initExplore() { } template -std::map> BFS::run(const T& root) { +std::map> BreadthFirstSearch::execute(const T& root) { std::map> tree; std::map graphExplore = initExplore(); std::queue Q; diff --git a/tree/breadth_first_tree.h b/tree/breadth_first_tree.h index c2c006d..04c4352 100644 --- a/tree/breadth_first_tree.h +++ b/tree/breadth_first_tree.h @@ -1,8 +1,8 @@ #ifndef BREADTH_FIRST_TREE_H_ #define BREADTH_FIRST_TREE_H_ -#include "algorithm/bfs.h" #include "out_tree.h" +#include "algorithm/breadth_first_search.h" using namespace graph; namespace tree { @@ -12,16 +12,15 @@ class BreadthFirstTree : public OutTree { public: BreadthFirstTree() = default; - BreadthFirstTree(Digraph G); + BreadthFirstTree(Digraph G, T root); BreadthFirstTree(std::map> G) : OutTree::OutTree(G) {} }; template -BreadthFirstTree::BreadthFirstTree(Digraph G) { - auto bfs = algo::BFS(G).run(1); - +BreadthFirstTree::BreadthFirstTree(Digraph G, T root) { + auto bfs = algo::BreadthFirstSearch(G).execute(root); Graph::adjMatrix = bfs; }