|
public class BubbleSort { //ClassName and FileName:BubbleSort
public static void main(String args[]) {
short source[] = {
540, 94, 458, 47, 64}; //source
short exchange = 0;
for (short pass = 1; pass < source.length; pass++) {
for (short i = 0; i < source.length - 1; i++) {
if (source > source[i + 1]) {
exchange = source; //swap
source = source[i + 1];
source[i + 1] = exchange;
} // if end
} //for end
} //for end
for (short i = 0; i < source.length; i++) {
System.out.print(source + " "); //show result on screen
}
} //main method end
} //class end |
|