AlgoPlus  v0.1.0
Public Member Functions | Friends | List of all members
graph< T > Class Template Reference

Class for Unweighted Graph. More...

#include <graph.h>

Public Member Functions

 graph (std::string _type, std::vector< std::pair< T, std::vector< T >>> _adj={})
 Constructor for the unweighted graph. More...
 
 graph (const graph &g)
 Construct a new graph object. More...
 
graphoperator= (const graph &g)
 operator = for the graph class More...
 
 ~graph ()
 Destroy the graph object.
 
void add_edge (T u, T v)
 add_edge function More...
 
bool has_edge (T start, T end)
 has_edge function. More...
 
void clear ()
 clear function Clearing the entire graph.
 
bool empty ()
 empty function Checks if a graph is empty.
 
size_t size ()
 size function More...
 
std::vector< T > dfs (T start)
 dfs function More...
 
std::vector< T > bfs (T start)
 bfs function More...
 
int64_t connected_components ()
 connected_components function. More...
 
bool cycle ()
 cycle function. More...
 
std::vector< T > topological_sort ()
 topological_sort function. More...
 
bool bipartite ()
 bipartite function. More...
 
std::vector< std::vector< T > > bridge (T start)
 bridge function. More...
 
int64_t scc ()
 scc(strongly connected components) function. More...
 
bool connected ()
 connected function. More...
 
int eulerian ()
 eulerian function. More...
 
void visualize ()
 visualize function. More...
 

Friends

std::ostream & operator<< (std::ostream &out, graph< T > &g)
 operator << for the graph class. More...
 

Detailed Description

template<typename T>
class graph< T >

Class for Unweighted Graph.

Constructor & Destructor Documentation

◆ graph() [1/2]

template<typename T >
graph< T >::graph ( std::string  _type,
std::vector< std::pair< T, std::vector< T >>>  _adj = {} 
)
inline

Constructor for the unweighted graph.

Parameters
__typetype of the graph, either "directed" or "undirected"
__adjvector<pair<T,vector<T>>, you can pass a vector of pairs to construct the graph without doing multiple add_edge.

◆ graph() [2/2]

template<typename T >
graph< T >::graph ( const graph< T > &  g)
inline

Construct a new graph object.

Parameters
gthe graph we want to copy

Member Function Documentation

◆ add_edge()

template<typename T >
void graph< T >::add_edge ( u,
v 
)
inline

add_edge function

Parameters
ufirst node
vsecond node

◆ bfs()

template<typename T >
std::vector< T > graph< T >::bfs ( start)

bfs function

Parameters
startstarting node of the bfs.
Returns
vector<T>, the path of the bfs.

◆ bipartite()

template<typename T >
bool graph< T >::bipartite

bipartite function.

Returns
true if the graph is bipartite.

◆ bridge()

template<typename T >
std::vector< std::vector< T > > graph< T >::bridge ( start)

bridge function.

Parameters
startstarting point of search for the bridges.
Returns
vector<vector<T>> the bridges of the graph.

◆ connected()

template<typename T >
bool graph< T >::connected

connected function.

Returns
true if a graph is connected.

◆ connected_components()

template<typename T >
int64_t graph< T >::connected_components

connected_components function.

Returns
the connected components(islands) of the graph.

◆ cycle()

template<typename T >
bool graph< T >::cycle

cycle function.

Returns
true if a cycle exist in the graph.

◆ dfs()

template<typename T >
std::vector< T > graph< T >::dfs ( start)

dfs function

Parameters
startstarting node of the dfs.
Returns
vector<T>, the path of the dfs.

◆ eulerian()

template<typename T >
int graph< T >::eulerian

eulerian function.

Returns
0 if a graph is not eulerian. 1 if a graph is semi-eulerian. 2 if a graph is eulerian.

◆ has_edge()

template<typename T >
bool graph< T >::has_edge ( start,
end 
)
inline

has_edge function.

Parameters
startstarting node.
endending node.
Returns
true if a direct edge from start to end exists. false if a direct edge from start to end does not exist.

◆ operator=()

template<typename T >
graph& graph< T >::operator= ( const graph< T > &  g)
inline

operator = for the graph class

Parameters
gthe graph we want to copy
Returns
graph&

◆ scc()

template<typename T >
int64_t graph< T >::scc ( )

scc(strongly connected components) function.

Returns
int64_t the number of scc's in the graph.

◆ size()

template<typename T >
size_t graph< T >::size

size function

Returns
size_t the size of the graph.

◆ topological_sort()

template<typename T >
std::vector< T > graph< T >::topological_sort

topological_sort function.

Returns
vector<T> the topological order of the elements of the graph.

◆ visualize()

template<typename T >
void graph< T >::visualize ( )

visualize function.

Returns
.dot file that can be previewed in vscode with graphviz.

Friends And Related Function Documentation

◆ operator<<

template<typename T >
std::ostream& operator<< ( std::ostream &  out,
graph< T > &  g 
)
friend

operator << for the graph class.

Returns
ostream &out for std::cout.

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