On Thu, 04 Dec 2003 13:04:29 +0800, Jonathan Wilson
<jo****@tpgi.com.au> wrote:
I am not sure what you mean by "I need to be able to store the elements
in this array somehow".
I meant sort not store.
Can one easliy sort the elements in a vector somehow?
Depending on how you use your "array", you might want to use
std::vector<my_pair> or std::list<my_pair>:
When you sort a vector, you are actually moving its elements around,
which could be slow if your vector is large. Also, if you have
pointers to elements of the vector, or iterators, and then sort it,
your pointers and iterators become invalid.
The list container, on the other hand, is not contiguous: Each element
could be anywhere in memory, and each element is chained to previous
and next via pointers. It is usually faster to sort, add and delete.
With std::list nothing is moved, as sorting, adding and deleting only
change pointers to previous and next. To use it you need to,
#include <list>
And to make sure that the STL is in your path.
Cheers!