Tom,
I didn't quite get your point, you mean you want to sort the characters like 'under' the numbers, as if the numbers are your first sort criteria, then the caracters?
In that case you can do something like:
<PRE>
var numAr=new Array(6,2,7,9,1,2,4,4,3);
var charAr=new Array("c","f","x","d","g","h","w","t","a");
public void sortArrays(int[] numAr,char[] charAr){
System.out.println("numAr: "+numAr);
System.out.println("charAr: "+charAr);
int tmpi;
char tmpc;
for(int m=0;m<numAr.length-1;m++){<br /> System.out.println("for loop, m is now "+m+", numAr["+m+"]="+numAr[m]+", numAr["+(m+1)+"]="+numAr[m+1]);<br /> while(numAr[m]>numAr[m+1]){
tmpi=numAr[m];
numAr[m]=numAr[m+1];
numAr[m+1]=tmpi;
tmpc=charAr[m];
charAr[m]=charAr[m+1];
charAr[m+1]=tmpc;
if(i>0)m--;
System.out.println("Sorting, m is now "+m);
}
}
System.out.println("numAr: "+numAr);
System.out.println("charAr: "+charAr);
for(int m=0;m<numAr.length-1;m++){<br /> System.out.println("charAr["+m+"]="+charAr[m]+", charAr["+(m+1)+"]="+charAr[m+1]+" ?"+(charAr[m]>charAr[m+1]));
while((numAr[m]==numAr[m+1])&&(charAr[m]>charAr[m+1])){
System.out.println("charAr["+m+"]="+charAr[m]+", charAr["+(m+1)+"]="+charAr[m+1]);
tmpc=charAr[m];
charAr[m]=charAr[m+1];
charAr[m+1]=tmpc;
if(i>0)m--;
}
}
System.out.println("numAr: "+numAr);
System.out.println("charAr: "+charAr);
}
</PRE>
Andy,
For instance, like this:
<PRE>
/* Declare this class in your file (at the end)*/
class mySortObject{
int intVal;
char charVal;
public mySortObject(int i,char c){
intVal=i;
charVal=c;
}
}
/* to declare an array of those:*/
mySortObject[] mySortArray;
/* add objects to the Array:
if you know the length when initialising, declare the array like this:*/
mySortObject[] mySortArray=new mySortObject[30];
/*
if not, you must copy the array into a new array with more elements whenever you add, like this:*/
mySortObject[] tmpMSA=new mySortObject[mySortArray.length+1];
for(int m=0;m<mySortArray.length;m++)tmpMSA[m]=mySortArray[m];<br /> /*then add the new Object:*/
tmpMSA[mySortArray.length]=new mySortObject(9,'m');
// and copy to the original Array (if you must)
mySortArray=tmpMSA;
/*Sorting your Array then boils down to:*/
Arrays.sort(mySortArray);
</PRE>
Note: The sort() function sorts after what would be the 'natural ordering' of the elements, what that means in this case you will have to find out...
Regards,
Marius
PS. This UBB code makes it hard to type the program code, indexes for instance...hope I got it right now...
[This message has been edited by Marius Holm (edited March 21, 2001).]