Parallel arrays vs array of structs

This is a discussion on Parallel arrays vs array of structs within the C++ Programming forums, part of the General Programming Boards category; How would you sort 5 parallel arrays in ascending order?...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    1

    Sorting Parallel Arrays

    How would you sort 5 parallel arrays in ascending order?
    Last edited by Brian Swisher; 04-03-2012 at 11:13 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,594
    I would prefer an array of structs as it is easier to handle and reason about, plus it easily allows for the use of standard algorithms like std::sort.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    100
    If I understand what you're talking about right, you basically want to create a sixth temporary array that tracks the position of where all the original elements are. Then sort whichever array you're basing the sort off of. As you do this, keep up with the changes in the temporary array. Once you're done sorting the first, use the sixth to sort two through five.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with parallel arrays!
    By khoavo123 in forum C Programming
    Replies: 2
    Last Post: 01-30-2012, 09:25 AM
  2. Modifying parallel arrays to arrays of structures
    By xkohtax in forum C Programming
    Replies: 7
    Last Post: 07-28-2011, 12:07 AM
  3. Replies: 3
    Last Post: 03-31-2009, 12:34 PM
  4. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  5. Parallel Arrays with Multiple Arrays
    By Billye Scott in forum C++ Programming
    Replies: 0
    Last Post: 03-02-2002, 10:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21