Thread: Parallel arrays vs array of structs

  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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 10: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, 04:07 PM
  5. Parallel Arrays with Multiple Arrays
    By Billye Scott in forum C++ Programming
    Replies: 0
    Last Post: 03-02-2002, 11:14 PM