linear-search-algorithm

线性查找算法

有一个数列: {1,8, 10, 89, 1000, 1234} ,判断数列中是否包含此名称

【顺序查找】 要求: 如果找到了,就提示找到,并给出下标值。

/**
 * @Author: Wizard
 * @Date: 2020/6/17 8:57
 */
public class OrderSearch {
    public static void main(String[] args) {
        int[] arr = {1, 8, 10, 89, 1000, 1234};
        System.out.println(OrderFind(arr, 10));
    }

    public static int OrderFind(int[] arr, int value) {
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] == value) {
                return i;
            }
        }
        return -1;
    }
}
Licensed under CC BY-NC-SA 4.0
Last updated on Oct 04, 2024 04:07 UTC
让过去的过去,给时间点时间
Built with Hugo
Theme Stack designed by Jimmy