diff --git a/Topplogical_sort.cpp b/Topplogical_sort.cpp new file mode 100644 index 0000000..67f78e1 --- /dev/null +++ b/Topplogical_sort.cpp @@ -0,0 +1,58 @@ + //Topological sorting + //only Directed Acyclic Graph(DAG) has a valid topological ordering. + //Algorithm : begin with any node exploring only unvisited nodes....on recursive callback of the DFS add current node to the topological ordering in reverse order + + #include + using namespace std; + + #define pb push_back + #define MAX 100001 + + bool visited[MAX]; + vector G[MAX]; + vector topological; + + void dfs(int node){ + + visited[node] = true; + + for(int i=0 ; i>nodes>>edges; + + memset(visited,false,sizeof(visited)); + + for(int i=0 ; i>u>>v; + G[u].pb(v); + } + + + for(int i=0 ; i