- package lhz.algorithm.chapter.two;
-
-
-
-
-
-
-
-
-
-
* 本文地址:http://mushiqianmeng.blog.51cto.com/3970029/733277
-
- public class BubbleSort {
-
- private static int[] input = new int[] { 2, 1, 5, 4, 9, 8, 6, 7, 10, 3 };
-
- public static void main(String[] args) {
- int endIndex = input.length - 1;
- for (int i = 0; i < endIndex; i++) {
- for (int j = endIndex; j > i; j--) {
- if (input[j] < input[j-1]) {
- int temp = input[j];
- input[j] = input[j-1];
- input[j-1] = temp;
- }
- }
- }
-
-
-
-
-
-
-
-
-
-
- printArray();
- }
-
- private static void printArray() {
- for (int i : input) {
- System.out.print(i + " ");
- }
- }
- }
本文转自mushiqianmeng 51CTO博客,原文链接:http://blog.51cto.com/mushiqianmeng/733277,如需转载请自行联系原作者