java-递归折半查找法

package m;

import java.util.*;

public class digui {

public static int[]data={1,3,5,7,9,11,33,55,77,99};

public static void main(String[]args)

{

System.out.println("eter the data you will find:");

Scanner scan=new Scanner(System.in);

int key=scan.nextInt();

if(zheban(key,0,9))

{

System.out.println("find ---");

}

else

{

System.out.println("failed--");

}

}

public static boolean zheban(int key,int low,int high)

{

int m;

if(low>high)

return false;

else

{

m=(low+high)/2;

if(key<data[m])

return zheban(key,low,m-1);

else if(key>data[m])

return zheban(key,m+1,high);

else if(data[m]==key)

{

System.out.println("the data is in the array "+(m+1));

return true;

}

}

return false;

}

}


本文出自 “hagar” 博客,谢绝转载!

java-递归折半查找法,布布扣,bubuko.com

java-递归折半查找法

上一篇:Jmeter察看结果树之HTML使用


下一篇:java-插入排序法