Please check ones my code is working fine or not?

hello @anshulgurawalia
yeah looks fine to me

sorry i think i have mentioned the wrong code the code for the topological sorting is : -

this one also look correct. the topo sort logic is also fine

This sorting is dependent on the order in which i am inserting the edge into the adj list ???

no order of insertion will not effect the order.
it will depend on->
a) the key (the smaller key will be processed first becuase u r using map, and in map by default elements are in sorted order)
b) the dependency of one vertex on other (the vertex that is not dependent will come first and then dependent vertices)

i am slightly confuse between ordered_map and map , both the same things or not

we have map and unordered map.

in map entries are in sorted order of key
in unordered map entries are not in sorted order

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.