What is the output of the following code?
#include <iostream>
#include <stack>
void topologicalSortUtil(int v, bool visited[], std::stack<int>& stack) {
visited[v] = true;
for (int u : adjList[v]) {
if (!visited[u]) {
topologicalSortUtil(u, visited, stack);
}
}
stack.push(v);
}
int main() {
// Graph initialization and input omitted for brevity
std::stack<int> stack;
bool visited[V] = {false};
for (int i = 0; i < V; i++) {
if (!visited[i]) {
topologicalSortUtil(i, visited, stack);
}
}
while (!stack.empty()) {
std::cout << stack.top() << " ";
stack.pop();
}
return 0;
}
Correct answer is option 'B'. Can you explain this answer?