Topological sort c++ 1 2 3 4 5 6 7 8 9 10 11 12stack<int> stk; for(int i=0; i<N; i++) if(deg[i] == 0) stk.push(i); vector<int> sorted; while(stk.size()){ int i = stk.top(); stk.pop(); sorted.push_back(i); for(int j : e[i]){ deg[j]--; if(deg[j] == 0) stk.push(j); } }