Refactor: Rename adjMatrix to adjList
This commit is contained in:
@@ -36,31 +36,31 @@ public:
|
||||
std::uint16_t E();
|
||||
|
||||
// Adjacency matrix representation
|
||||
std::map<T, std::set<T>> adjMatrix;
|
||||
std::map<T, std::set<T>> adjList;
|
||||
|
||||
friend std::ostream& operator<<<>(std::ostream& os, Graph<T>& G);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Graph<T>::~Graph() {
|
||||
adjMatrix.clear();
|
||||
adjList.clear();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto Graph<T>::vertices() {
|
||||
return std::views::keys(adjMatrix);
|
||||
return std::views::keys(adjList);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::uint16_t Graph<T>::V() {
|
||||
return static_cast<std::uint16_t>(adjMatrix.size());
|
||||
return static_cast<std::uint16_t>(adjList.size());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::uint16_t Graph<T>::E() {
|
||||
std::uint16_t edges = 0;
|
||||
for (const auto& u : vertices()) {
|
||||
edges += static_cast<std::uint16_t>(adjMatrix[u].size());
|
||||
edges += static_cast<std::uint16_t>(adjList[u].size());
|
||||
}
|
||||
return static_cast<std::uint16_t>(edges);
|
||||
}
|
||||
@@ -69,8 +69,8 @@ template<typename T>
|
||||
std::ostream& operator<<(std::ostream& os, Graph<T>& G) {
|
||||
os << "V: " << G.V() << " E: " << G.E() << '\n';
|
||||
for (const auto& u : this->vertices()) {
|
||||
if (!this->adjMatrix[u].empty()) {
|
||||
for (const auto& v : this->adjMatrix[u]) {
|
||||
if (!this->adjList[u].empty()) {
|
||||
for (const auto& v : this->adjList[u]) {
|
||||
os << u << "->" << v << ' ';
|
||||
}
|
||||
os << '\n';
|
||||
|
||||
Reference in New Issue
Block a user