Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > lexicographical sorting

Reply
Thread Tools

lexicographical sorting

 
 
tim.lino@gmail.com
Guest
Posts: n/a
 
      03-30-2007
Dear all,

I would like to sort the elements in a vector in a lexicographical
order. The elements are defined as:

class E
{
public:
int x;
int y;
}

where x is the first rank and y is the second rank in the
lexicographical order. Suppose I have vector<E>, how I can sort E in a
lexicographical order? Is it any built-in function to do that?

Thank you.

 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      03-30-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> I would like to sort the elements in a vector in a lexicographical
> order. The elements are defined as:
>
> class E
> {
> public:
> int x;
> int y;
> }
>
> where x is the first rank and y is the second rank in the
> lexicographical order. Suppose I have vector<E>, how I can sort E in a
> lexicographical order? Is it any built-in function to do that?


You need to (a) overload operator< for the type E or (b) specialize
std::less<> for the type E. Then, std::sort() will just sort any range for
you.

Alternatively, you could ditch the class E and just use std:air<int,int>
instead. Then, the appropriate overload for operator< would be defined
already (and, yes, it does lexicographic order).


Best

Kai-Uwe Bux
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting list vs sorting vector boltar2003@boltar.world C++ 2 07-06-2010 09:40 AM
fired event Sorting which wasn't handled - sorting and SelectedIndexChanged Jason ASP .Net Web Controls 0 10-04-2006 02:19 PM
How to: Windows Quick Tip - How to Force Alphabetic Sorting Silverstrand Reviews & How-To's 3 08-23-2005 08:59 AM
Lexicographical sort for numarray Edward C. Jones Python 5 04-27-2005 11:48 PM
sorting by multiple criterias (sub-sorting) Tom Kirchner Perl Misc 3 10-11-2003 05:16 PM



Advertisments