Skip to content

Commit

Permalink
Modified: change 'Infinite' from template parameter to constructor pa…
Browse files Browse the repository at this point in the history
…rameter
  • Loading branch information
huanmie committed Jul 19, 2022
1 parent 1b52464 commit eb3b5ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Graph/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

int main()
{
Graph<std::string> graph{
Graph<std::string> graph(std::numeric_limits<int>::max(), {
{ "A", 9, "B" }, { "A", 5, "C" }, { "C", 2, "B" },
{ "A", 3, "D" }, { "B", 5, "D" }, { "D", 2, "C" },
{ "D", 2, "E" }, { "D", 5, "B" }, { "C", 4, "E" },
{ "B", 2, "F" }, { "F", 1, "E" }, { "C", 5, "F" },
};
});
graph.AddEdge("C", "D") = 3;
auto out_path = graph.GetOutPath("C");
out_path.clear();
Expand Down
10 changes: 5 additions & 5 deletions Graph/Graph.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

template<typename Vertex, typename Weight = int, Weight Infinite = std::numeric_limits<Weight>::max()>
template<typename Vertex, typename Weight = int>
class Graph
{
using AdjacencyMatrix = std::unordered_map<Vertex, std::unordered_map<Vertex, Weight>>;
Expand All @@ -11,13 +11,13 @@ class Graph
std::function<std::vector<PathType>(const Vertex&, const Vertex&, Compare)> best_path;

public:
constexpr static Weight INFINITE = Infinite;
const Weight INFINITE;

Graph() = default;
Graph(const Weight& Infinite) :INFINITE(Infinite) {}

Graph(auto&&... rests) { Construct(std::forward<decltype(rests)>(rests)...); }
Graph(const Weight& Infinite, auto&&... rests) :INFINITE(Infinite) { Construct(std::forward<decltype(rests)>(rests)...); }

Graph(std::initializer_list<std::tuple<Vertex, Weight, Vertex>> list)
Graph(const Weight& Infinite, std::initializer_list<std::tuple<Vertex, Weight, Vertex>> list) :INFINITE(Infinite)
{
for (auto&& element : list)
AddEdge(std::get<0>(element), std::get<2>(element)) = std::get<1>(element);
Expand Down

0 comments on commit eb3b5ed

Please sign in to comment.