Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > sort with vector<struct>

Reply
Thread Tools

sort with vector<struct>

 
 
Oliver Block
Guest
Posts: n/a
 
      09-14-2005
Hi,

can anyone if it is enough to place the elements of a structure in a
different order when you want to sort it.

for example sort by name:

struct item 1 {
String name;
int age;
}

or otherwise sort by age:

struct item 2 {
int age;
String name;
}

I never used that routine. Would that work and are there better ways?

bye,

Oliver

 
Reply With Quote
 
 
 
 
peter.koch.larsen@gmail.com
Guest
Posts: n/a
 
      09-14-2005

Oliver Block skrev:

> Hi,
>
> can anyone if it is enough to place the elements of a structure in a
> different order when you want to sort it.
>
> for example sort by name:
>
> struct item 1 {
> String name;
> int age;
> }
>
> or otherwise sort by age:
>
> struct item 2 {
> int age;
> String name;
> }


It is not.
>
> I never used that routine. Would that work and are there better ways?
>
> bye,
>
> Oliver

You need to write a predicate "less" that compares the struct according
to your requirement. Google around - there are lots of examples.

/Peter

 
Reply With Quote
 
 
 
 
Oliver Block
Guest
Posts: n/a
 
      09-16-2005

schrieb:

> You need to write a predicate "less" that compares the struct according
> to your requirement. Google around - there are lots of examples.



thank you! I added a class cmp which implements just Operator().

bye,

Oliver

 
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
Re: When will Thunderbird support sort in place (in context sort)? Ron Natalie Firefox 0 02-02-2006 04:38 AM
The Colourised Bewitched -- sort of OK....... sort of! anthony DVD Video 26 06-28-2005 04:39 AM
xsl:sort lang="es" modern vs. tradidional Spanish sort order nobody XML 0 06-01-2004 06:25 AM
What is faster? C++ vector sort or sort in database JerryJ C++ 11 04-28-2004 10:23 PM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57