冒泡排序

  1. //冒泡排序
  2. int[] a = {1, 5, 23, 52, 123, 521, 3215, 234};
  3. //决定对比的轮次
  4. for (int i = 0; i < a.length - 1; i++) {
  5. //决定对比的个数
  6. for (int j = 0; j < a.length - 1 - i; j++) {
  7. if (a[j] > a[j + 1]) {
  8. int temp = a[j];
  9. a[j] = a[j + 1];
  10. a[j + 1] = temp;
  11. }
  12. }
  13. }