"ch.a...@..." <ch.a...@...> wrote:
> Hi I am using boost collection class. 
> 
> I did sorting e.g apply a quick/bubble sort algo  , but i want
> to do sorting using multiple criteria. how we can implement
> using boost. 
> 
> Do boost have any  classes or functions through which I can
> easily sort the data using multiple options?

I see you've already posted in Boost archives on Google. The
answer you got there is what I would expect.

I've only seen Boost, not used it, but the STL sorts are all
based on supplying a 'less than' predicate.

If you have multiple predicates (prefixed lt below), the
general technique to combine them is...

       lt1(a, b)
  or (!lt1(b, a) and  lt2(a, b))
  or (!lt1(b, a) and !lt2(b, a) and  lt3(a, b))
  or (!lt1(b, a) and !lt2(b, a) and !lt3(b, a) and lt4(a, b))
  ...

Another way to look at it is...

  if ( lt1(a, b)) return true;   /* a <  b */
  if (!lt1(b, a)) return false;  /* a == b */

  if ( lt2(a, b)) return true;   /* a <  b */
  if (!lt2(b, a)) return false;  /* a == b */

  if ( lt3(a, b)) return true;   /* a <  b */
  if (!lt3(b, a)) return false;  /* a == b */

  ...
  if ( ltN(a, b)) return true;   /* a <  b */

  return false;

Note the principle:
  if a < b is false, then a >= b.
  if b < a is also false, then b >= a,
    in which case, a <= b and a >= b, so a == b

-- 
Peter

Reply via email to