Stay hungry, stay foolish !

I've failed over and over and over again in my life. And that is why I succeed.

算法导论学习2.1-3 查找问题

public class Search {
	public static void main(String[] args)
	{
		int[] a = {1,2,3,4,5,6,7,8,9,0};
		int v = 11;
		System.out.print("v in a[" + search_v(v,a) + "]  (a[-1] means " + v + " is not in the line.)");
	}
	
	static int search_v(int v, int[] a)
	{
		int i;
		for(i = 0; i < a.length; i++)
		{
			if(a[i] == v)
				{
					return i;
				}
		}
		return -1;		
	}	
}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wangbaomi/article/details/7399108
个人分类: 算法导论 JAVA
想对作者说点什么? 我来说一句

<em>算法导论</em>_原书第3版

2018年05月27日 0B 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭