Skip to content

Added Topological Sorting #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 20, 2019
Merged

Added Topological Sorting #171

merged 2 commits into from
Feb 20, 2019

Conversation

abhiy13
Copy link
Contributor

@abhiy13 abhiy13 commented Nov 20, 2018

Added an implementation of Topological Sort for Directed Graphs.

reverse(ans.begin(), ans.end());
}
int main(){
cin >> n >> m;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add cout<<"enter number of vertices and edges = "; or something similar so the user knows what input has to be given.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed !

topological_sort();
cout << "Topological Order : \n";
for(int v : ans) {
cout << v << ' ';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you are converting 1-indexed to 0-indexed after input, you should convert 0-indexed to 1-indexed before output too. (User will input 1 vertex but will see 0 in output)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@ashwek ashwek merged commit a3ddfcd into TheAlgorithms:master Feb 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants