最佳答案
我有一个收藏:
List<VPair<Item, List<Item>> dependencyHierarchy;
The first item in pair is some object (item) and the second one is a collection of the same type objects that the first one depends on. I want to get a List<Item>
in order of dependency, so there are not items that depend on the first element and so on (no cycled dependency!).
输入:
Item4 depends on Item3 and Item5 Item3 depends on Item1 Item1 does not depend on any one Item2 depends on Item4 Item5 does not depend on any one
结果:
Item1 Item5 Item3 Item4 Item2
谢谢你。
解决方案:
拓扑排序 (感谢 Loic Février的创意)
还有