Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
graph::Graph Class Reference
Inheritance diagram for graph::Graph:
[legend]
Collaboration diagram for graph::Graph:
[legend]

Public Member Functions

 Graph (size_t N, const std::vector< std::pair< int, int > > &undirected_edges)
 Populate the adjacency list for each vertex in the graph. Assumes that evey edge is a pair of valid vertex indices. More...
 
int number_of_vertices () const
 

Public Attributes

std::vector< std::vector< int > > neighbors
 for each vertex it stores a list indicies of its neighbors
 

Detailed Description

Class for representing a graph as an adjacency list. Its vertices are indexed 0, 1, ..., N - 1.

Constructor & Destructor Documentation

◆ Graph()

graph::Graph::Graph ( size_t  N,
const std::vector< std::pair< int, int > > &  undirected_edges 
)
inline

Populate the adjacency list for each vertex in the graph. Assumes that evey edge is a pair of valid vertex indices.

Parameters
Nnumber of vertices in the graph
undirected_edgeslist of graph's undirected edges
62  {
63  neighbors.resize(N);
64  for (auto &edge : undirected_edges) {
65  neighbors[edge.first].push_back(edge.second);
66  neighbors[edge.second].push_back(edge.first);
67  }
68  }
Here is the call graph for this function:

Member Function Documentation

◆ number_of_vertices()

int graph::Graph::number_of_vertices ( ) const
inline

Function to get the number of vertices in the graph

Returns
the number of vertices in the graph.
74 { return neighbors.size(); }
Here is the call graph for this function:

The documentation for this class was generated from the following file:
std::vector::resize
T resize(T... args)
std::vector::size
T size(T... args)
std::vector::push_back
T push_back(T... args)
graph::Graph::neighbors
std::vector< std::vector< int > > neighbors
for each vertex it stores a list indicies of its neighbors
Definition: lowest_common_ancestor.cpp:77