java查找算法之顺序查找

查找算法之顺序查找

顺序查找太简单了,写在博客似乎降低档次,但是,查找算法一家人就得要整整齐齐。

package cn.ycl.dataStructures.Search;
public class SeqSearch {
	public static void main(String[] args) {
		int arr[] = { -1, 6, 9, 3, 90, 56, 2 };
int seqSearch = seqSearch(arr, 90);
System.out.println(seqSearch);
	}
	public static int seqSearch(int arr[] ,int findVal) {
        for (int i = 0; i < arr.length; i++) {
			if (findVal==arr[i]) {
				return i;
			}
		}
        return -1;
	}
}
posted @ 2022-06-14 08:50  道祖且长  阅读(29)  评论(0)    收藏  举报