Push every node to the queue which has no incoming edge
for ( int i = 0 ; i < V ; i ++ ) { if ( indeg [ i ] == 0 ) { q . Enqueue ( i ) ; } } List < int > res = new List < int > ( ) ; while ( q . Count > 0 ) { int u = q . Dequeue ( ) ; res . Add ( u ) ;