sorting

How would you sort more than two corresponding arrays at once? I have the following code, which works just fine, but everytime I try to add another array to sort with it, it never seems to work. Example: I want to sort dog names by their weight. The dog names are stores in an array called names[ ], and the weights are stored in weights[ ]. Element 0 in names[ ] corresponds with element 0 in weights[ ], and so on. But, there's another array called furs[ ] that stores the colors of each dog's fur, and corresponds with the other two, and it needs to change along with weights[ ] and names[ ] also. How can I fit that in?

for(int e=0; e<72-1; e++)

{

for(int g=0; g<72; g++)

{

if(weights[g]>weights[g+1])

{

double Temp = weights[g];

weights[g] = weights[g+1];

weights[g+1] = Temp;

String Temp2 = names[g];

names[g] = names[g+1];

names[g+1] = Temp2;

}

}

}

[1317 byte] By [chacMS15a] at [2007-11-26 19:22:19]
# 1

You wouldn't.

You'd define a class called Dog that contains name, weight, fur, and whatever other dog attributes you're modeling, create a single array of Dog, and sort that.

http://java.sun.com/docs/books/tutorial/java/javaOO/index.html

[url=http://www.onjava.com/lpt/a/3286]Making Java Objects Comparable[/url]

http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html

http://www.javaworld.com/javaworld/jw-12-2002/jw-1227-sort.html

jverda at 2007-7-9 21:42:45 > top of Java-index,Java Essentials,New To Java...