It is sufficient to find any arbitrary predicate P
such that P(a,a)==false
, P(a,b) && P(b,a)==false
, P(a,b) && P(b,c)
implies P(a,c)
and !P(a,b) && !P(b,a)
implies a == b
. Less-then satisfies this property, as thus greater-then. But they're far from the only possibilities.
You can now sort your collection by predicate P
, and all elements which are equal will be adjacent. In your case, define P(E1,E2)=true, P(E2,E3)=true
, etc.