TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
graph::topological_sort::Graph Class Reference

Class that represents a directed graph and provides methods for manipulating the graph. More...

Collaboration diagram for graph::topological_sort::Graph:
[legend]

Public Member Functions

 Graph (int nodes)
 Constructor for the Graph class.
 
void addEdge (int u, int v)
 Function that adds an edge between two nodes or vertices of graph.
 
const std::vector< std::vector< int > > & getAdjacencyList () const
 Get the adjacency list of the graph.
 
int getNumNodes () const
 Get the number of nodes in the graph.
 

Private Attributes

int n
 
std::vector< std::vector< int > > adj
 

Detailed Description

Class that represents a directed graph and provides methods for manipulating the graph.

Definition at line 38 of file topological_sort.cpp.

Constructor & Destructor Documentation

◆ Graph()

graph::topological_sort::Graph::Graph ( int nodes)
inline

Constructor for the Graph class.

Parameters
nodesNumber of nodes in the graph

Definition at line 48 of file topological_sort.cpp.

48: n(nodes), adj(nodes) {}

Member Function Documentation

◆ addEdge()

void graph::topological_sort::Graph::addEdge ( int u,
int v )
inline

Function that adds an edge between two nodes or vertices of graph.

Parameters
uStart node of the edge
vEnd node of the edge

Definition at line 55 of file topological_sort.cpp.

55{ adj[u].push_back(v); }

◆ getAdjacencyList()

const std::vector< std::vector< int > > & graph::topological_sort::Graph::getAdjacencyList ( ) const
inline

Get the adjacency list of the graph.

Returns
A reference to the adjacency list

Definition at line 61 of file topological_sort.cpp.

61 {
62 return adj;
63 }

◆ getNumNodes()

int graph::topological_sort::Graph::getNumNodes ( ) const
inline

Get the number of nodes in the graph.

Returns
The number of nodes

Definition at line 69 of file topological_sort.cpp.

69{ return n; }

Member Data Documentation

◆ adj

std::vector<std::vector<int> > graph::topological_sort::Graph::adj
private

Definition at line 41 of file topological_sort.cpp.

◆ n

int graph::topological_sort::Graph::n
private

Definition at line 40 of file topological_sort.cpp.


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