C++ Library Extensions 2022.12.09
To help learn modern C++ programming
059-graph01.cpp
Go to the documentation of this file.
1#include "059-graph01.hpp"
2
5
7
9{
10 graph_t g;
11
12 g.emplace_back("Tom", 1, 3);
13 g.emplace_back("Sophia", 0, 2);
14 g.emplace_back("Amie", 1, 3, 4);
15 g.emplace_back("Albert", 0, 2, 4);
16 g.emplace_back("Michelle", 2, 3);
17
18 stream <<"graph node list - \n"
19 << g << endl;
20
21 size_t size = g.size();
22 stream << "List adjacent nodes" << endl;
23 for(size_t index = 0; index < size; ++index)
24 {
25 stream << g[index] << endl;
26 }
27
28 stream << endl;
29 stream << "List node information" << endl;
30 for(size_t index = 0; index < size; ++index)
31 {
32 stream << g.node_info(index) << endl;
33 }
34
35 stream << endl;
36 stream << "List node value and adjacent node list" << endl;
37 for(size_t index = 0; index < size; ++index)
38 {
39 stream << g.node_value(index) << " - "
40 << g.adjacency_node_list(index) << endl;
41 }
42
43 stream << endl;
44 stream << "List node value and adjacent node values" << endl;
45 for(size_t index = 0; index < size; ++index)
46 {
47 stream << g.node_value(index)
48 << " - " << g.adjacent_node_values(index) << endl;
49 }
50
51 stream << endl;
52 stream << "Accessing each individual nodes" << endl;
53 for(size_t index = 0; index < size; ++index)
54 {
55 auto [value, adjacency_list] = g[index];
56
57 stream << "Node value: " << value
58 <<" - Adjacency list: " << adjacency_list << endl;
59 }
60}
61
62int main()
63{
65}
tpf::sstream stream
Definition: 059-graph01.cpp:3
auto endl
Definition: 059-graph01.cpp:4
void test_graph_data_structure()
Definition: 059-graph01.cpp:8
int main()
Definition: 059-graph01.cpp:62
size_t size()
decltype(auto) adjacency_node_list(size_t node_index)
Definition: 059-graph01.hpp:40
void emplace_back(EleType &&value, Type &&index0, Types &&... indices)
decltype(auto) node_value(size_t node_index)
Definition: 059-graph01.hpp:81
auto adjacent_node_values(size_t node_index)
Definition: 059-graph01.hpp:53
node_info_t node_info(size_t node_index) const
Definition: 059-graph01.hpp:91
constexpr auto endl
Definition: tpf_output.hpp:973