title: Algorithm for sorting loosely comparable data?
body: <p>Let's say I have an unsorted list of four objects: <code>[B, C, A, D]</code>.</p>
  
  <p>All four objects are of the same type, and:</p>
  
  <pre><code>  (A &gt; B),
    (C &gt; D),
    (A != C or D)
    (B != C or D)
    (C != A or B)
    (D != A or B).
  </code></pre>
  
  <p>By <code>!=</code> I mean that they are neither less-than, equal-to, or greater-than the other objects.</p>
  
  <p>I need to "sort" the list such that <code>A</code> will always come before <code>B</code>, and <code>C</code> will always come before <code>D</code>. Beyond those two requirements, I have no demand on the ordering of the list; therefore, given the previously described list, the sort function should return either <code>[A, B, C, D]</code> or <code>[C, D, A, B]</code>.</p>
  
  <p>As for the cause of this problem, I am trying to sort an array of <code>java.lang.Class</code> objects based on their relationships to each other. For example, if <code>A</code> is the super-class/super-interface of <code>B</code>, then <code>A</code> is less-than <code>B</code>. If <code>A</code> extends/implements <code>B</code>, then is <code>A</code> greater-than <code>B</code>. If <code>A</code> is <code>B</code>, then obviously <code>A</code> equals <code>B</code>. Otherwise, <code>A</code> is completely non-comparable to<code></code>B.</p>