一.排序常見的兩種方法 乙個是冒泡法排序 乙個是直接排序 效能上冒泡法排序 優於直接排序
/***
* @title: bubblesort
* @description:使用冒泡法排序 (公升序)
* @author: lizhang
* @date: 2023年11月19日 上午9:33:01
* @param arr 需要排序的陣列
* @throws
*/public static void bubblesort(int arr) }}
}/**
* * @title: selectsort
* @description:直接排序(公升序)
* @author: lizhang
* @date: 2023年11月19日 上午9:37:45
* @param arr 需要排序的陣列
* @throws
*/public static void selectsort(int arr) }}
}二.使用二分法查詢陣列中是否存在某個值
/***
* @title: halfseach
* @description:二分法查詢陣列中是否有傳入的數字
* @author: lizhang
* @date: 2023年11月19日 上午10:15:29
* @param arr 陣列
* @param key 查詢的值
* @return int 返回-1表明次數組沒有 key值 反之則返回陣列的下標
* @throws
*/public static int halfseach(int arr,int key) else if(keymax)
mid = (max+min)/2;
}return mid;
}三.陣列的去重
/***
* @title: removerepetition
* @description: 去除陣列中重複的元素 返回乙個新的陣列
* @author: lizhang
* @date: 2023年11月21日 下午4:43:50
* @param arr 原陣列
* @return int 新陣列
* @throws
*/public int removerepetition(int arr) }}
//建立新陣列
int newarr = new int[arr.length-count];
//將原陣列中的不重複元素放入到新陣列中
int index = 0;
for(int i = 0;i}if(!flag)
}return newarr;
}
陣列的基本操作
預備知識 在用下標訪問元素時,vector使用的是vector size type型別,而陣列下標的 正確型別是size t 程式清單 執行結果 the elements of array1 is below array1 0 0 array1 1 1 array1 2 2 array1 3 3 a...
陣列的基本操作
學習過程中遇到了運算元組的多種方法,暫時沒有時間,先記錄下來,有時間再詳細補充。ok,可以開始了,最近在學習vue.js,其中有一部分是介紹運算元組的方法,想了想,也沒記住幾個,所以就記錄下來。查詢了一波,還缺少了一些內容,以下沒有序號的為新增內容 sort 用於對陣列的元素進行排序。arrayob...
陣列的基本操作
如下 package classdemo public class testarray 2.使用隨機數初始化陣列 double mylist new double 10 for int i 0 i mylist.length i 3.列印陣列 for int i 0 i mylist.length ...