I got this algorithm that sort int[] a from low to high.
public static void sortering(int[] a){
int temp;
for(int i = 0; i < a.length; i++){
for(int j = i + 1; j < a.length; j++){
if(a[i] > a[j]){
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
}
What i want to do is to reverse it, make it sort from high to low. I thought this would be a walk in the park doing something like this:
public static void sorteringU(int[] a){
int temp;
for(int i = a.length; i < a.length; i--){
for(int j = i - 1; j < a.length; j--){
if(a[i] > a[j]){
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
}
I was wrong, this apparently does nothing. Anyone willing to help?
Edit: Thx Jesper and Satya, it worked.
if(a[i] > a[j])toif(a[i] < a[j]).if(a[i] > a[j])this is where logic is hidden not in loop taversing