常用算法
1 二分查找:
非递归 public static int biSearch(int []array,int a){ int lo=0; int hi=array.length-1; int mid; while(lo<=hi){ mid=(lo+hi)/2; if(array[mid]==a){ return mid+1; }else if(array[mid]<a){ lo=mid+1; }else{ hi=mid-1; } } return -1; } 递归实现: public static int sort(int []array,int a,int lo,int hi){ if(lo<=hi){ int mid=(lo+hi)/2; if(a==array[mid]){ return mid+1; } else if(a>array[mid]){ return sort(array,a,mid+1,hi); }else{ return sort(array,a,lo,mid-1); } } return -1; }
快速排序:参考 https://www.cnblogs.com/coderising/p/5708801.html