//氣泡排序
public class bubblesorttest
public static void bubblesort(int array)
for(int i = 0; i < array.length - 1; i++) //其實此處可以換成i是最大的
for(int j = 0; j < array.length - i - 1; j++)
if(array[j] > array[j + 1])
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
//列印每趟排序
system.out.println("第" + (i + 1) + "趟排序");
for(int k = 0; k < array.length; k++)
system.out.print(array[k] + " ");
system.out.println();
public static void main(string args)
int array = ;
bubblesort(array);
//查詢search
public class arraysearchtest
;int value = 11;
int index = search(a, value);
system.out.println(index);
system.out.println("-----------------");
int b = new int;
int index2 = binarysearch(b , 10);
system.out.println(index2);
氣泡排序 二分查詢
include include include using namespace std int bsearch int t,int n,int x 二分查詢 return null inline void swap int a,int b void init int t,int n for int ...
氣泡排序 二分查詢
二分查詢 在label中無法顯示陣列 解決方法 string str 定義 字串str並賦初值 後 str str myarray i tostring 用str 接收已排序陣列再在label中顯示。剛開始寫二分查詢時找到分支 if sortarray mid num labelres.text 已...
氣泡排序,二分查詢
氣泡排序 lst 88,5,8,6,1,23 for a in range len lst 記錄內部排序的次數 i 0 while i len lst 1 把最大值移動到右端 if lst i lst i 1 比較,lst i lst i 1 lst i 1 lst i 交換 i i 1 print...