TheAlgorithms/C++ 1.0.0
All the 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.

Definition at line 35 of file dijkstra_greedy.cpp.

Constructor & Destructor Documentation

◆ Graph()

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

Constructs a graph.

Parameters
Vnumber of vertices of the graph

Definition at line 44 of file dijkstra_greedy.cpp.

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

Definition at line 68 of file dijkstra_greedy.cpp.

68 {
69 this->edges[src][dst] = weight;
70 }

Member Data Documentation

◆ edges

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

Definition at line 38 of file dijkstra_greedy.cpp.

38{};

◆ vertexNum

int greedy_algorithms::dijkstra::Graph::vertexNum = 0

Definition at line 37 of file dijkstra_greedy.cpp.


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