标签:sso 下标 冒泡 amp str tom tostring ++ sort
/**
* 二分查找法
*/
public static void dichotomySort(int[] a,int b){
Arrays.sort(a);
System.out.println(Arrays.toString(a));
int c = 0;
int d = a.length-1;
while(d>=c){
int f = (c+d)/2;
if(b>a[f]){
c=f+1;
}else if(b == a[f]){
System.out.println("要查的数的下标为:"+f);
break;
}else if(b<a[f]){
d = d-1;
}
}
}
/**
* 快速排序
*/
public static void speedinessSort(int[] a){
int x = 0;
int y = a.length-1;
int z = (x+y)/2;
while(x<a.length-1){
if(a[x]>a[z] && a[x] > a[z]){
int t = a[x];
a[x] = a[z];
a[z] = t;
}
x++;
y--;
}
}
/**
* 插入排序
*/
public static void inserSort(int[] c){
for (int i = 0; i < c.length; i++) {
for (int k = i+1; k < c.length; k++) {
if(c[i]>c[k]){
int t = c[k];
c[k] = c[i];
c[i] = t;
}
}
}
}
/**
* 冒泡排序
*/
public static void bubbleSort(int[] d){
for (int i = 0; i < d.length; i++) {
for (int k = 0; k < d.length-i-1; k++) {
if(d[i]>d[k]){
int t = d[k];
d[k] = d[i];
d[i] = t;
}
}
}
}
标签:sso 下标 冒泡 amp str tom tostring ++ sort
原文地址:https://www.cnblogs.com/xiaokaivip/p/9368092.html