Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
问题陈述:当给定任意两个数之间的二元关系时,对 n 个对象 a1,a2...an 进行排序。
比如说 5 个对象 a1、a2、a3、a4 和 a5
a1 < a5 a4 < a2 a3 < a5 a2 < a1 a1 < a3
所以顺序是 a4 a2 a1 a3 a5 任何算法来做到这一点
一种简单的方法是保留一个矩阵relationships[x, y] = true if x < y并将该矩阵用作您喜欢的排序算法中的比较函数。
relationships[x, y] = true if x < y
然而,拓扑排序可能会更有效。