TopologicalSort
TopologicalSort[g] gives a list of vertices of g in topologically sorted order for a directed acyclic graph g.
TopologicalSort[{v -> w, ...}]uses rules v -> w to specify the graph g.
Examples
TopologicalSort[Graph[{1 -> 2, 2 -> 3, 1 -> 3}]]TopologicalSort[{a -> b, b -> c, a -> c}]Please visit the official Wolfram Language Reference for more details.