I've gotten the basics of insertion code but I'm stuck on how to compare it with another condition other then (list by A-Z, Z-A)
for the example a list of staff ranks were given :
public static final String[] staffrank = {
"Trainee",
"Junior",
"Senior",
"Administrator",
};
I have a method to compare
If it returns 0 means they're of equal rank (staff 1 and staff 2)
if it returns -1 means staff 1 is lower rank than staff 2
if it returns 1 means staff 1 is higher rank than staff 2
Then I have a list of staffs in void main
Staff[] snames;
int countname=0;
snames = new Staff[50];
snames[countname++] = new Staff("Amy","Trainee");
snames[countname++] = new Staff("Annie","Junior");
snames[countname++] = new Staff("Tom","Administrator");
snames[countname++] = new Staff("Dave","Trainee");
snames[countname++] = new Staff("Gary","Junior");
snames[countname++] = new Staff("Donna","Senior);
then the insertion sort compare code
public static void insertionSortbyRank(Staff[] snames, int countname) {
//insertion sort
for(int i =1; i < countname; i++) {
int j = i;
int comparerank = Staff.compareRank(snames[j],snames[j-1]);
String name = snames.getName();
String rank = snames.getRank();
//if staff is lower rank
if(comparerank==-1) {
Then i'm unsure what to put in this while loop
since if i just do the following, it returns a A-Z / Z-A thing instead
while( j >0 && rank.compareToIgnoreCase(snames[j-1].getRank()) > 0)) {
list[j].rank =[j-1].rank;
list.[j].name = [j-1].name;
j--;
}
then the end is replacing the new values
snames[j].name = name;
snames[j].rank = rank;
Any help would be appreciated..thank you