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

D

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
 
I

Ian Collins

Daz said:
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.
 
D

Daz

Ian said:
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.

Thanks Ian! I will look into that. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top