import java.util.Arrays; /* Comparable requires a class to implement the function CompareTo */ public class Vec3 implements Comparable { int x[]; public Vec3() { x = new int[3]; x[0] = x[1] = x[2] = 0; } public Vec3(int x0, int x1, int x2) { x = new int[3]; x[0] = x0; x[1] = x1; x[2] = x2; } public void set(int x0, int x1, int x2) { x[0] = x0; x[1] = x1; x[2] = x2; } public int compareTo( Object o ) { Vec3 v = (Vec3) o; for(int i=0;i<3;i++) { if( x[i] < v.x[i] ) return(-1); else if( x[i] > v.x[i] ) return(1); } return(0); } public String toString() { String s = "( "+Integer.toString(x[0]); for(int i=1;i<3;i++) { s += ", " + Integer.toString(x[i]); } s += " )"; return(s); } public static void main(String argv[] ) { Vec3 thing[] = new Vec3[5]; thing[0] = new Vec3( 5, 3, 2 ); thing[1] = new Vec3( 5, 1, 4 ); thing[2] = new Vec3( 1, 4, 3 ); thing[3] = new Vec3( 1, 4, 3 ); thing[4] = new Vec3( 6, 3, 2 ); Arrays.sort( thing ); for(int i=0;i<5;i++) System.out.println( thing[i] ); } }