Click here to Skip to main content
15,898,923 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
So basically, I have a bunch of arrays which all come together to form a table.
And I want to put it into increasing order

What I have tried:

For x = 1 to 6
        Console.WriteLine("{0,-10} {1,-6} {2,-7} {3,-7} {4,-10} {5,-5}", name(x), sum, wins, lost, roundsWon, knockout)
next
Posted
Updated 25-Oct-18 19:17pm
v2
Comments
CHill60 25-Oct-18 5:16am    
What is wrong with the code you have? What happens/does not happen?
RV2020 25-Oct-18 5:21am    
Currently, it just outputs it like it has been entered (charlotte then victoria then dhruv then petra then rauha then isabel) rather than in increasing order (isabel then dhruv then petra then charlotte then victoria then rauha)

1 solution

The way I would do it is to throw away your separate arrays, and create a "container class" which holds a single persons details: name and results.
Then create an array of these and populate each instance accordingly.
You can then order the array by name or results by reordering the array and the other information about the person automatically moves with it.
 
Share this answer
 
Comments
OriginalGriff 25-Oct-18 5:28am    
It's an ordinary class that just contains data - it doesn't try to do anything with it.
OriginalGriff 25-Oct-18 5:43am    
Yes, but it's a lot more complicated, because you have to remember to perform the same actions on both arrays, or you will not keep related information together.

One way to get round that is to have a separate "indexes" array - and instead of going directly to the two arrays you have, you use that to provide you with the index to both of the others.

So if you want the second item in a sequence, you fetch the number from the second element of the indexes array, and use that to access the names array and the results array.
When you want to sort the data by name or results, you swap the indexes around instead of the actual data in the name or results arrays.

Make sense?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900