|
-
May 27th, 1999, 09:25 AM
#1
multiple index on an array
I have an 'array' of objects that I need to have indexed in 2 ways, i.e. I need to be able to loop thru the array in 2 different orders. I don't want to create 2 arrays and sort them differently. How do I solve this?
///Anders
-
May 27th, 1999, 10:11 AM
#2
Re: multiple index on an array
for the second index try using an array of pointer to the original data. Have it sorted based on what it points to.
-
May 27th, 1999, 10:13 AM
#3
Re: multiple index on an array
Can't be done without a second array or an ugly function that would really slow down response. I have always handled it with a second array of pointers to the objects - this way I don't use up much memory or increase allocations. Since you don't have to manage the pointers - there should be no problems with cleaning up.
-
May 27th, 1999, 10:20 AM
#4
Re: multiple index on an array
I tend to use a class derived from the base array class and overiding all the functions for add/remove/get and add a second array as a member of this new class, and keep it up to date during all add/deletes. I then have two GetAt functions
GetAtSort1 / GetAtSort2, and I also have a function that says set sort mode so that the generic GetAt / operator[] return the correctly sorted array entry.
HTH,
Chris
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|