Created
March 3, 2015 13:18
-
-
Save rohith2506/80d208b5e28471865120 to your computer and use it in GitHub Desktop.
Topological sorting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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