how can one implement an ascending sorting algorithm in array classes?
So Far I read few methods of sorting array but how about array of classes?
Any help is appreciated




Posted 24 October 2011 - 09:59 PM
Posted 24 October 2011 - 10:07 PM
Posted 24 October 2011 - 10:11 PM
Posted 24 October 2011 - 10:12 PM
This post has been edited by novacrazy: 24 October 2011 - 10:16 PM
Posted 24 October 2011 - 10:17 PM
Posted 24 October 2011 - 10:20 PM
class A implements Comparable<A>{
int x;
A(int x){ this.x = x; }
public int getX(){ return x; }
public int compareTo(A other){ return this.x - other.x; }
}
A[] objects = new A[3];
Random rand = new Random();
for(int i = 0; i < objects.length; i++){
objects[i] = new A(rand.nextInt());
}
for(int i = 0; i < objects.length; i++){
for(int j = i+1; j < objects.length; j++){
System.out.println("Value: " + i + "( " + objects[i].getX() + " ), Value " + j + "( " + objects[j].getX() + "): " + objects[i].compareTo(objects[j]));
}
}
Posted 24 October 2011 - 10:25 PM
Posted 24 October 2011 - 10:26 PM
temp <-- one one <-- two two <-- temp
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
