标签:images 冒泡排序 div span stat [] select 分享 .com
1 //选择排序对数据进行升序排序 2 public static void selectSortArray(int[] arr){ 3 for(int i = 0; i<arr.length-1;i++){ 4 for(int j = i+1;j<arr.length;j++){ 5 if(arr[i]>arr[j]){ 6 int temp = arr[j]; 7 arr[j] = arr[i]; 8 arr[i] = temp; 9 } 10 } 11 } 12 } 13
//冒泡排序对数据进行升序排序 public static void bubbleSortArray(double[] arr){ for(int i = 0;i<arr.length-1;i++){ for(int j = 0;j<arr.length-1-i;j++){ if(arr[j]>arr[j+1]){ double temp = arr[j+1]; arr[j+1] = arr[j]; arr[j] = temp; } } } }
public static int binarySearch(int[] arr,int key){ int max,min,mid; max = arr.length-1; min = 0; while(min<=max){ mid = (max+min)/2; if(key>arr[mid]){ min = mid+1; }else if (key<arr[mid]) { max = mid-1; }else{ return mid; } } return -1; }
标签:images 冒泡排序 div span stat [] select 分享 .com
原文地址:http://www.cnblogs.com/zxf-java/p/7270674.html