Skip to content

Instantly share code, notes, and snippets.

@rohith2506
Created March 3, 2015 13:18
Show Gist options
  • Save rohith2506/80d208b5e28471865120 to your computer and use it in GitHub Desktop.
Save rohith2506/80d208b5e28471865120 to your computer and use it in GitHub Desktop.
Topological sorting
void toposort(vector<int> v, stack<int> stck, vector<bool> visited){
visited[i] = true;
for(int j=0; j<v[i].size(); j++){
if(visited[i] == true)
toposort(v,stck,visited);
}
stck.push(v);
}
void driver(vector<int> v){
vector<bool> visited(n,false);
for(int i=0; i<v.size(); i++){
if(visited[i])
toposort(v,visited,stck);
}
while(!stck.empty()){
cout << stck.top();
stck.pop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment