Introduction - If you have any usage issues, please Google them yourself
There is a directed graph stored in the adjacent table. Trial design an algorithm, depth-first search strategy by the topology of its sort. And to test your example picture on the right algorithm.