> Benjamin Scott-2 wrote:
> > "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. 
<snip>
> > 
> > I'd recommend a Function Pointer as follows:
> > 
> > void Sort(int Length, Nodes *ToSort(), Node
> > **Decider(Node one,Node Two))
> > {};

Even making some corrections, this is...

Not a good suggestion to someone using C++.
A bad suggestion to someone using the C++ STL.
An awful suggestion to someone using the C++ Boost libraries.

Below is an STL sample per my previous reply to the OP...

  #include <algorithm>
  #include <iostream>
  
  struct item { std::string s; int i; } array[9] =
    {
      { "C", 1 },
      { "A", 2 },
      { "B", 1 },
      { "B", 2 },
      { "A", 1 },
      { "B", 3 },
      { "C", 2 },
      { "A", 1 },
      { "C", 2 }
    };
  
  bool operator < (const item &lhs, const item &rhs)
  {
    return      (lhs.s < rhs.s)
        or (not (rhs.s < lhs.s) and (lhs.i < rhs.i));
  }
  
  std::ostream &cout_item(const item &item)
  {
    return std::cout << item.s << ' ' << item.i << std::endl;
  }
  
  int main()
  {
    std::cout << "Unsorted:\n";
    std::for_each(array, array + 9, cout_item);
  
    std::sort(array, array + 9);
  
    std::cout << "\nSorted:\n";
    std::for_each(array, array + 9, cout_item);
  }

-- 
Peter

Reply via email to