# Algorithms_in_C++: graph::Graph Class Reference

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

  N | number of vertices in the graph
  undirected_edges | list of graph's undirected edges

{
neighbors.resize(N);
for (auto &edge : undirected_edges) {
neighbors[edge.first].push_back(edge.second);
neighbors[edge.second].push_back(edge.first);
}
}
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.

{
return neighbors.size();
}
Here is the call graph for this function:

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

- graph/lowest_common_ancestor.cpp

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:78