package com.yaphetzhao.sort;
/**
* Created by YaphetZhao
* on 2016/11/24.
* 冒泡法排序
*/
public class BubbleSort {
public static void main(String[] args) {
int[] numbers = {0, 1, 3, 5, 6, 9, 0, 4, 2, 2, 6, 7, 5, 3, 9, 6};
int temp;
int size = numbers.length;
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
if (numbers[i] > numbers[j]) {
temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
}
}
}
String numbers_str = "";
for (int aNumber : numbers) {
numbers_str += aNumber + ",";
}
System.out.print(numbers_str);
}
}
网友评论