Thread: How to sort by size

  1. #1
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244

    How to sort by size

    Hi people! I would love any help on this one:
    I have a list of lists list<list<int>*> and I need to sort it by the size of the inner list. I only need to know how to declare a Compare function (I saw this kind of function in references, but I donīt know how to declare it).
    So, I coulde use: myList.sort( compare_function );
    Nothing more to tell about me...
    Happy day =)

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    28
    I think it the compare function should look like this.

    Code:
    bool Compare(const list<int> &l1, const list<int> &l2)
    {
        return l1.size() < l2.size();
    }
    That should sort in increasing order according to size.

  3. #3
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244
    Actually, after a lot of study, I had discover that the compare function returns an int, I think this is because an int can show three results: less, equal and greater.
    But thanks for the reply
    Nothing more to tell about me...
    Happy day =)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. heap sort problem
    By Cpro in forum C++ Programming
    Replies: 2
    Last Post: 02-04-2008, 04:54 AM
  2. for loop with sort issues
    By redmondtab in forum C Programming
    Replies: 10
    Last Post: 10-09-2006, 10:36 AM
  3. Error with a vector
    By Tropicalia in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2006, 07:45 PM
  4. Sorting
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 11-10-2003, 05:21 PM
  5. radix sort and radix exchange sort.
    By whatman in forum C Programming
    Replies: 1
    Last Post: 07-31-2003, 12:24 PM