heey, i've made a game and i want to sort an array on the score
(example: a[] = {5,9,2,6,3,2} = {2,2,3,5,6,9})
but then i wanted to sort another array on the same way as the first
example
a[ ] = {2,6,5,8} --> {2,5,6,8}
b[ ] = {6,9,2,5} --> {6,2,9,5}
yes?
how can i do it?
Answers
You should make a class having both values, instead of separate arrays. See From several arrays to classes.
Thus, correlated values are kept together, and you can define on which field you do the sorting. Search for Comparator or Comparable from the main site.
Don't forget Processing got a function to sort arrays called sort():
http://processing.org/reference/sort_.html
GoToLoop, the problem isn't to sort arrays, the problem is to apply the sorting of one array to another.
There is this article:
http://wiki.processing.org/w/Sorting_with_Comparable
And I have this old test I made once:
I don't think sequence
{6,2,9,5}
is an ordered list! 8-}Nevertheless, I did an attempt as well:
a[ ] = {2,6,5,8} --> {2,5,6,8} //<- this gets sorted[
b[ ] = {6,9,2,5} --> {6,2,9,5} //< - but this don't.
There is a relationship that is kept:
a 2 b 6
a 6 b 9
a 5 b 2
a 8 b 5
I think this is why PhiLho suggested the object with a natural order of sorting.