Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1687936
  • 博文数量: 347
  • 博客积分: 9328
  • 博客等级: 中将
  • 技术积分: 2680
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-29 23:45
文章分类

全部博文(347)

文章存档

2016年(1)

2013年(4)

2012年(207)

2011年(85)

2010年(50)

分类: Java

2012-12-20 10:31:26

http://www.cnblogs.com/darejoy/archive/2010/05/27/1745871.html


  1. private static int find(int[] arySource, int target, int start, int end)
  2. {
  3.     if (start == end)
  4.     {
  5.         if (arySource[start] == target)
  6.         {
  7.             return start;
  8.         }
  9.         else
  10.         {
  11.             return -1;
  12.         }
  13.     }
  14.     else if (start > end)
  15.     {
  16.         return -1;
  17.     }

  18.     int curIndex = -1;
  19.     curIndex = (start + end) / 2;

  20.     int middleValue = arySource[curIndex];
  21.     if (target == middleValue)
  22.     {
  23.         return curIndex;
  24.     }
  25.     else if (target < middleValue)
  26.     {
  27.         return find(arySource, target, start, curIndex - 1 );
  28.     }
  29.     else
  30.     {
  31.         return find(arySource, target, curIndex + 1, end);
  32.     }
  33. }

阅读(3075) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~