TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Static Public Member Functions | |
static bool | isCyclicDFS (Graph const &graph) |
static bool | isCyclicBFS (Graph const &graph) |
Private Types | |
enum | nodeStates : uint8_t { not_visited = 0 , in_stack , visited } |
Static Private Member Functions | |
static bool | isCyclicDFSHelper (AdjList const &adjList, std::vector< nodeStates > *state, unsigned int node) |
Check if a directed graph has a cycle or not.
This class provides 2 methods to check for cycle in a directed graph: isCyclicDFS & isCyclicBFS.
Definition at line 159 of file cycle_check_directed_graph.cpp.
|
private |
Definition at line 161 of file cycle_check_directed_graph.cpp.
|
inlinestatic |
Check if a graph has cycle or not.
This function uses BFS to check if a graph is cyclic or not.
graph | which needs to be evaluated for the presence of cycle. |
Definition at line 250 of file cycle_check_directed_graph.cpp.
|
inlinestatic |
Driver function to check if a graph has a cycle.
This function uses DFS to check for cycle in the graph.
graph | which needs to be evaluated for the presence of cycle. |
State of the node.
It is a vector of "nodeStates" which represents the state node is in. It can take only 3 values: "not_visited", "in_stack", and "visited".
Initially, all nodes are in "not_visited" state.
Definition at line 213 of file cycle_check_directed_graph.cpp.
|
inlinestaticprivate |
Helper function of "isCyclicDFS".
adjList | is the adjacency list representation of some graph. |
state | is the state of the nodes of the graph. |
node | is the node being evaluated. |
Definition at line 171 of file cycle_check_directed_graph.cpp.