What is the best way to sort a partially ordered list?

这一生的挚爱 提交于 2019-12-03 14:00:00

This is called topological sorting.

The standard algorithm is to output a minimal element, then remove it and repeat until done.

Do several sorts. First sort according to the first rule, then according to the second one and so on. Should work, unless your rules contain contradictions. sure easy enough to implement.

You could repeatedly call make_heap, pop_heap in C++ with the sequence at hand.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!