CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 1999
    Location
    Mora,Sweden
    Posts
    38

    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


  2. #2
    Join Date
    May 1999
    Location
    Canada
    Posts
    36

    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.


  3. #3
    Guest

    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.


  4. #4
    Join Date
    May 1999
    Posts
    667

    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
  •  





Click Here to Expand Forum to Full Width

Featured