标签:nbsp 选择 turn min ati static 冒泡排序 for style
int[] arr = new int[] { 12, 43, 5, 16, 32, 56, 106 }; //冒泡排序 for (int x = 0; x < arr.length-1; x++) { for (int y = 0; y < arr.length-1-x; y++) { if(arr[y]>arr[y+1]) { int temp = arr[y]; arr[y] = arr[y+1]; arr[y+1] = temp; } } }
int[] arr = new int[] { 12, 43, 5, 16, 32, 56, 106 }; //选择排序 for (int x = 0; x < arr.length-1; x++) { for (int y = x+1; y < arr.length; y++) { if(arr[x]>arr[y]) { int temp = arr[x]; arr[x] = arr[y]; arr[y] = temp; } } }
//数组必须有序 int[] arr = new int[] {5,12,16,32,43,56,106}; //二分查找 public static int erfenFind(int[] arr) { arr = new int[] {5,12,16,32,43,56,106}; int min,mid,max; int key =45; min = 0; max = arr.length - 1; while(min<=max) { mid = (min+max)/2; if(key>arr[mid]) { min = mid + 1; } else if(key<arr[mid]) { max = mid - 1; } else { return mid; } } return -1; }
标签:nbsp 选择 turn min ati static 冒泡排序 for style
原文地址:https://www.cnblogs.com/greenPrairie/p/10549953.html