陣列氣泡排序,選擇排序,逆序,折半查詢,遍歷方法

2021-08-09 23:56:23 字數 788 閱讀 9633

public class hello2;

// 呼叫方法是有先後順序的

//xuanze(arr);

//maopao(arr);

//nixu(arr);

//bianli(arr);

int index=zheban(arr,5);

system.out.println(index);

}//折半查詢方法(其陣列必須是有序資料從小到達排列)

public static int zheban(int arr,int key)else if (key

max=mid-1;

}else

}return -1;

}//陣列的氣泡排序

public static void maopao(int arr)}}

}/*//氣泡排序2

public static void sortarray(int arr)}}

}*///陣列的選擇排序

public static void xuanze(int arr) } }

}//定義方法實現陣列的逆序

public static void nixu(int arr)

}//陣列遍歷方法

public static void bianli(int arr)else

}system.out.println();

}//求最大值max

public static void max(int arr)

}system.out.println(max);}}

選擇 氣泡排序,折半查詢

include void selectsort int num,int length void swap int num,int i int j void butttlesort int num,int length int main int argc,const char argv 計算陣列的長度...

java基礎 選擇排序 氣泡排序 折半查詢法

1 選擇排序 選擇排序,逐次選擇最大的或是最小的元素,放到起始位置或是末尾位置,直到排序完成 package sort 選擇排序 選擇排序 在未排序的陣列中找到最大或最小的,存放在起始位置 再從剩餘的未排序元素中尋找最大或最小的,然後放在末尾位置 以此類推,直到所有元素均排序完畢 author 空空...

陣列 氣泡排序 選擇排序 插入排序

package arr 我自己的陣列類 author guosheng public class arrayself public arrayself int chang 新增方法 郭勝 public void insert long value 降序插入 public void insertbys...