摘要: /** 选择排序 1.将maxIndex赋值为数组第一个元素的索引 2.与下一个值分别做比较,若小于下一个值则将较大值的索引赋值给maxIndex 3.比较结束后将最大值置于最后,将maxIndex重新赋值为0 4.下一轮比较开始 */ public class CollectionDemo1 { 阅读全文
posted @ 2022-11-19 11:37 都是废话说了 阅读(25) 评论(0) 推荐(0)
摘要: 二分查找(折半查找) 前提:排好顺序的数据 //元素存在 返回索引,否则返回-1 public static int binarySearch(int[] arr, int data) { int left = 0; int right = arr.length - 1; while(left <= 阅读全文
posted @ 2022-11-01 10:20 都是废话说了 阅读(16) 评论(0) 推荐(0)