public class OrderSearch {
public static void main(String[] args) {
int[] array = new int[]{1, 2, 3, 4};
int index = orderSearch(array, 3);
if (index == -1) {
System.out.println("没有找到~");
} else {
System.out.println("index = " + index);
}
}
public static int orderSearch(int[] array, int value) {
for (int i = 0; i < array.length; i++) {
if (array[i] == value) {
return i;
}
}
return -1;
}
}
线性查找法
最新推荐文章于 2023-10-13 10:17:59 发布