How can I make this sorting algorithm?
modules = {
2:[4], # element 2 must be after element 4
1:[],
3:[2,4], # element 3 must be after 2 and 3 elements
4:[1] # element 4 must be after element 1
}
Result [1, 4, 2, 3]
by conditions.
That's called a topological sort. Makefiles do it, and there's a standard UNIX utility called tsort
that will do it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.