标签:
用什么语言思想都一样,换种形式表达而已
package mytest; public class Mycode { public static void main(String[] args){ int[]arr = {9,8,3,5,2}; bubbleSort(arr); printArray(arr); } public static void printArray(int[] arr){ for(int i = 0; i < arr.length; i++){ System.out.println(arr[i]+" "); } } public static void bubbleSort(int[] arr){ for(int i = 0; i < arr.length-1; i++){ for(int j = 0; j < arr.length-i-1; j++){ if(arr[j] > arr[j+1]) { int tmp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = tmp; } } } } }
标签:
原文地址:http://www.cnblogs.com/rain-1/p/4830674.html