Java数组实现冒泡排序
package com.my.algorithm.sort;
public class BubbleSort {
/**
* @param args
*/
public static void main(String[] args) {
int [] s = {90, 85, 55, 94, 77, 77, -10, 100, 0};
bubbleSort(s);
for(int i=0;i<s.length;i++){
System.out.print(s[i]);
System.out.print(' ');
}
}
public static void bubbleSort(int[] s){
int temp = 0;
for(int i=0;i<s.length-1;i++){
for(int j=0;j<s.length-i-1;j++){
if (s[j] > s[j+1]){
temp = s[j];
s[j] = s[j+1];
s[j+1] = temp;
}
}
}
}
}
输出结果:-10 0 55 77 77 85 90 94 100