Refactor: Rename adjMatrix to adjList
This commit is contained in:
@@ -14,8 +14,8 @@ class BreadthFirstSearch {
|
||||
public:
|
||||
BreadthFirstSearch() = default;
|
||||
|
||||
BreadthFirstSearch(std::map<T, std::set<T>> adjMatrix)
|
||||
: adjMatrix(adjMatrix) {}
|
||||
BreadthFirstSearch(std::map<T, std::set<T>> adjList)
|
||||
: adjList(adjList) {}
|
||||
|
||||
// Traverse whole graph using the BFS search, and save the tree graph
|
||||
// which is created when visiting new vertices (Breadth First Tree)
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
bool query(const T& root, const T& target);
|
||||
private:
|
||||
// Represents the graph on which the algorithm will be executed
|
||||
std::map<T, std::set<T>> adjMatrix;
|
||||
std::map<T, std::set<T>> adjList;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@@ -40,7 +40,7 @@ std::map<T, std::set<T>> BreadthFirstSearch<T>::execute(const T& root) {
|
||||
const auto v = Q.front();
|
||||
Q.pop();
|
||||
|
||||
for (const auto& u : adjMatrix[v]) {
|
||||
for (const auto& u : adjList[v]) {
|
||||
if (!visited[u]) {
|
||||
visited[u] = true;
|
||||
tree[v].insert(u);
|
||||
@@ -65,7 +65,7 @@ bool BreadthFirstSearch<T>::query(const T& root, const T& target) {
|
||||
|
||||
if (v == target) return true;
|
||||
|
||||
for (const auto& u : adjMatrix[v]) {
|
||||
for (const auto& u : adjList[v]) {
|
||||
if (!visited[u]) {
|
||||
visited[u] = true;
|
||||
Q.push(u);
|
||||
|
||||
Reference in New Issue
Block a user