18 #ifndef DFS_TOPO_SORT_HH_ 19 #define DFS_TOPO_SORT_HH_ 40 void topological_sort_util(
unsigned int v,
bool visited[],
41 stack<unsigned int>& stc);
60 for (
uint i=0; i<nv_; ++i)
69 inline void add_edge(
unsigned int v,
unsigned int w)
84 stack<unsigned int>& stc)
92 for (i = adj_[v].begin(); i != adj_[v].end(); ++i)
94 topological_sort_util(*i, visited, stc);
105 stack<unsigned int> stc;
108 bool* visited =
new bool[nv_];
109 for (
unsigned int i = 0; i < nv_; i++)
116 for (
unsigned int i = 0; i < nv_; i++)
117 if (visited[i] ==
false)
118 topological_sort_util(i, visited, stc);
122 vec.resize(stc.size());
123 while (!stc.empty()) {
124 vec[stc.size()-1] = stc.top();
void add_edge(unsigned int v, unsigned int w)
void topological_sort_util(unsigned int v, bool visited[], stack< unsigned int > &stc)
A function used by topological_sort.
vector< unsigned int > topological_sort()
unsigned int nv_
Number of vertices.
void clear()
Clear content of adjacency lists.
~DfsTopoSort()
Destructor.
DfsTopoSort(unsigned int nv)
Constructor.
list< unsigned int > * adj_
Pointer to an array containing adjacency lists.