Create Solution for topological sort in cpp #2472 #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This Pull Request addresses issue DHEERAJHARODE#2472 by demonstrating Topological sorting, which is a linear ordering of vertices in a directed acyclic graph (DAG) in such a way that for every directed edge (u, v), vertex u comes before v in the ordering.
In this code,
The Graph class represents a directed graph using an adjacency list. The addEdge method is used to add directed edges to the graph. The topologicalSortUtil method is a helper function that performs a depth-first search (DFS) and pushes vertices onto a stack based on their topological order. The topologicalSort method initiates the topological sorting by calling topologicalSortUtil for each unvisited vertex.
Related Issue
Fixes DHEERAJHARODE#2472
Checklist
•I have tested the code and verified that it works as expected. •I have added comments and explanations for the code for better understanding. •The code follows the project's coding style and conventions. •The code has been formatted and does not contain any linting issues.