TOPOLOGICAL SORING IS DONE ON DIRECTED ACYCLIC GRAPH (DAG)
void kahnsalgo(){
queue<int>q;
vector<int>count=Count_indegree();
for(int i=0;i<v;i++)if(count[i]==0)q.push(i);
while(!q.empty()){
int x=q.front();
cout<<x<<" ";
q.pop();
for(int y:adj[x]){
count[y]--;
if(count[y]==0)q.push(y);
}
}
}
No comments:
Post a Comment