MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / topoSortDFS

Function topoSortDFS

CPP/graphseries.cpp:173–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173vector<int> topoSortDFS(vector<int> arr[], int n)
174{
175 stack<int> s;
176 vector<int> vis(n, 0);
177 for (int i = 0; i < n; i++)
178 {
179 if (!vis[i])
180 {
181 findTopoSortDFS(i, arr, s, vis);
182 }
183 }
184
185 vector<int> ans;
186 while (!s.empty())
187 {
188 ans.push_back(s.top());
189 s.pop();
190 }
191
192 return ans;
193}
194
195// BFS (Kahn's Algorithm)
196vector<int> topoSortBFS(vector<int> arr[], int n)

Callers

nothing calls this directly

Calls 4

findTopoSortDFSFunction · 0.85
push_backMethod · 0.80
topMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected