By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,681 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

Creating a list of multiple element rows, and sorting them.

P: n/a
Daz
Hi everyone.

I am trying to make a program which handles about 70 different objects,
of the same type. The properties are as follows:

std::string ItemName
int ItemType
int Calories
int Weight
int Density

I am looking for a way of sorting the list during the several stages of
their handling.processing, but I don't have a clue where to start. The
list will need to be sorted 3 times, once by Calories, once by Weight,
and then again by Density.

Obviously, I can put each property into a vector, and then sort them,
but this doesn't sort the others into their respective positions (they
need to be handled as rows of data). I am sure that I am either not
realizing the full potential of a vector, or I need to use/create
something else, such as a custom class based on a vector, but I am
really not sure.

I would appreciate any suggestions.

Thanks in advance.

Daz

Jul 2 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Daz wrote:
Hi everyone.

I am trying to make a program which handles about 70 different objects,
of the same type. The properties are as follows:

std::string ItemName
int ItemType
int Calories
int Weight
int Density

I am looking for a way of sorting the list during the several stages of
their handling.processing, but I don't have a clue where to start. The
list will need to be sorted 3 times, once by Calories, once by Weight,
and then again by Density.
For a small data set like this, you might as well use 3 maps
(std::map<int,Object*>), and you your three sort criteria as the keys.

--
Ian Collins.
Jul 2 '06 #2

P: n/a
Daz

Ian Collins wrote:
For a small data set like this, you might as well use 3 maps
(std::map<int,Object*>), and you your three sort criteria as the keys.

--
Ian Collins
Thanks Ian! I will look into that. :)

Jul 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.