aboutsummaryrefslogtreecommitdiff
path: root/comp6771/3/src/client.cpp
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-13 18:00:17 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-13 18:00:17 +1100
commit98cef5e9a772602d42acfcf233838c760424db9a (patch)
tree5277fa1d7cc0a69a0f166fcbf10fd320f345f049 /comp6771/3/src/client.cpp
initial commit
Diffstat (limited to 'comp6771/3/src/client.cpp')
-rw-r--r--comp6771/3/src/client.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/comp6771/3/src/client.cpp b/comp6771/3/src/client.cpp
new file mode 100644
index 0000000..ca3c30e
--- /dev/null
+++ b/comp6771/3/src/client.cpp
@@ -0,0 +1,75 @@
+#include "gdwg_graph.h"
+
+#include <iostream>
+#include <string>
+
+auto main() -> int {
+ /*
+ auto g = gdwg::graph<std::string, int>{};
+ g.insert_node("hello");
+ g.insert_node("how");
+ g.insert_node("are");
+ g.insert_node("you?");
+
+ g.insert_edge("hello", "how", 5);
+ g.insert_edge("hello", "are", 8);
+ g.insert_edge("hello", "are", 2);
+
+ g.insert_edge("how", "you?", 1);
+ g.insert_edge("how", "hello", 4);
+
+ g.insert_edge("are", "you?", 3);
+
+ std::cout << g << "\n";
+
+ auto g2 = gdwg::graph<std::string, int>(g);
+
+ std::cout << g2 << "\n";
+
+ // This is a structured binding.
+ // https://en.cppreference.com/w/cpp/language/structured_binding
+ // It allows you to unpack your tuple.
+ for (const auto& [from, to, weight] : g) {
+ std::cout << from << " -> " << to << " ";
+ if (weight.has_value()) {
+ std::cout << "(weight " << *weight << ")\n";
+ }
+ else {
+ std::cout << "(no weight)\n";
+ }
+ }
+ */
+
+ using graph = gdwg::graph<int, int>;
+ auto const v = std::vector<std::tuple<int, int, std::optional<int>>>{
+ {4, 1, -4},
+ {3, 2, 2},
+ {2, 4, std::nullopt},
+ {2, 4, 2},
+ {2, 1, 1},
+ {4, 1, std::nullopt},
+ {6, 2, 5},
+ {6, 3, 10},
+ {1, 5, -1},
+ {3, 6, -8},
+ {4, 5, 3},
+ {5, 2, std::nullopt},
+ };
+
+ auto g = graph{};
+ for (const auto& [from, to, weight] : v) {
+ g.insert_node(from);
+ g.insert_node(to);
+ if (weight.has_value()) {
+ g.insert_edge(from, to, weight.value());
+ }
+ else {
+ g.insert_edge(from, to);
+ }
+ }
+ g.insert_node(64);
+
+ auto out = std::ostringstream{};
+ out << g;
+ std::cout << g << '\n';
+}