Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
greedy_algorithms::dijkstra::Graph Class Reference

Wrapper class for storing a graph. More...

Collaboration diagram for greedy_algorithms::dijkstra::Graph:
[legend]

Public Member Functions

 Graph (const int V)
 Constructs a graph.
 
void add_edge (int src, int dst, int weight)
 Adds an edge to the graph.
 

Public Attributes

int vertexNum = 0
 
std::vector< std::vector< int > > edges {}
 

Detailed Description

Wrapper class for storing a graph.

Constructor & Destructor Documentation

◆ Graph()

greedy_algorithms::dijkstra::Graph::Graph ( const int V)
inlineexplicit

Constructs a graph.

Parameters
Vnumber of vertices of the graph
44 {
45 // Initialize the array edges
46 this->edges = std::vector<std::vector<int>>(V, std::vector<int>(V, 0));
47 for (int i = 0; i < V; i++) {
48 edges[i] = std::vector<int>(V, 0);
49 }
50
51 // Fills the array with zeros
52 for (int i = 0; i < V; i++) {
53 for (int j = 0; j < V; j++) {
54 edges[i][j] = 0;
55 }
56 }
57
58 this->vertexNum = V;
59 }

Member Function Documentation

◆ add_edge()

void greedy_algorithms::dijkstra::Graph::add_edge ( int src,
int dst,
int weight )
inline

Adds an edge to the graph.

Parameters
srcthe graph the edge should be added to
dstthe position where the edge should be added to
weightthe weight of the edge that should be added
Returns
void
68 {
69 this->edges[src][dst] = weight;
70 }

Member Data Documentation

◆ edges

std::vector<std::vector<int> > greedy_algorithms::dijkstra::Graph::edges {}
38{};

The documentation for this class was generated from the following file: