package it.heimasjl;
public class Sort {
public static void main(String[] args) {
int[] a = { 9, 6, 3, 8, 2, 0, 1 };
int[] b = {5,8,7,4,9,6,2,1};
Help sort = new Help();
sort.maxToMin(a);
sort.minToMax(b);
Sort s =new Sort();
s.print(a);
s.print(b);
}
private void print(int [] a){
for(int b:a){
System.out.print(b);
}
System.out.println();
}
}
class Help {
public void maxToMin(int[] a) {
for (int i = a.length - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (new Integer(a[j]).compareTo(new Integer(a[j + 1])) < 0) {
swap(a, j, j + 1);
}
}
}
}
public void minToMax(int[] a) {
for (int i = a.length - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (new Integer(a[j]).compareTo(new Integer(a[j + 1])) > 0) {
swap(a, j, j + 1);
}
}
}
}
public void swap(int[] a, int x, int y) {
int temp;
temp = a[x];
a[x] = a[y];
a[y] = temp;
}
} |