Home arrow static arrow Java Programming [Archive] - SORT 2D ARRAY OF OBJECTS ??? Help Please
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - SORT 2D ARRAY OF OBJECTS ??? Help Please
This topic has 6 replies on 1 page.

Posts:303
Registered: 9/4/98
SORT 2D ARRAY OF OBJECTS ??? Help Please  
Jul 26, 2004 5:01 AM



 

Hi I have an array of 5 objects each in 3 different arrays

int A[ ] = { 1,2,3,4,5};
int B[ ] = { 2,3,4,5,6};
String C [ ] = { "L","M","N" ,"O","P"};

All these arrays corrospondes 1 : 1 : 1 factor.

Ex: -
1 : 2 : L [ first set of values, ]

similarly others folow in sequencial order.....

If i am suppose to SORT the ARRAY A and fetch the corrosponding values accordingly....

Can some body Help me.

TRx in advance

 

Posts:8,813
Registered: 10/4/00
Re: SORT 2D ARRAY OF OBJECTS ??? Help Please  
Jul 26, 2004 5:19 AM (reply 1 of 6)



 
Write code to sort A. Once you have done that, instead of just swapping items in A, swap items in all arrays.
 

Posts:303
Registered: 9/4/98
Re: SORT 2D ARRAY OF OBJECTS ??? Help Please  
Jul 26, 2004 5:24 AM (reply 2 of 6)



 
Hi

How to Apply the Sort factor for a condition where Array A,B are of int type and Array C is of String type ????

Can some body Tell me HOW to use ARRAY SORT for the same.........

 

Posts:1,995
Registered: 12/10/00
Re: SORT 2D ARRAY OF OBJECTS ??? Help Please  
Jul 26, 2004 5:26 AM (reply 3 of 6)



 
Looking at this question and your other [url http://forum.java.sun.com/thread.jsp?thread=541179&forum=31&message=2623449]thread[/url] you wil get faster and better help if you stop posting and waiting for answers and read some beginner's book.

Anyway, if you are not obliged to hold your data in separate arrays then you can create a class to encapsulate each data item from these arrays and then order your items as you want to.

Mike
 

Posts:303
Registered: 9/4/98
Re: SORT 2D ARRAY OF OBJECTS ??? Help Please  
Jul 26, 2004 5:32 AM (reply 4 of 6)



 
Hi

I have heard of Array .sort

Can some body Tell me How to Use the same for an Array of Object


Arrays.sort( X , new Comparator() {

.....
}

Please


with rehards
Karthik

 

Posts:24,036
Registered: 2/3/03
Re: SORT 2D ARRAY OF OBJECTS ??? Help Please  
Jul 26, 2004 5:57 AM (reply 5 of 6)



 
Can some body Tell me How to Use the same for an
Array of Object

You've just shown how. You pass the Object[] and a Comparator. What question do you have about this?
 

Posts:1,872
Registered: 2/12/03
Re: SORT 2D ARRAY OF OBJECTS ??? Help Please  
Jul 27, 2004 1:40 PM (reply 6 of 6)



 
Array.sort() will not work for your case.

you want to sort accorind to array A // by the way..don't use capital for variable names
if you perform sort using Array.sort on A..array B and C are not sorted (according to A 1:1:1 ratio)

an easy sort algorithm is the bubble sort. with alittle modification to the swapping

so instead of
temp = a
a = b
b = temp;

you will have
temp1 = a;
temp2 = b;
temp3 = c;

a = a[i+1];
b = b[i+1];
the rest you can do
 
This topic has 6 replies on 1 page.