Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6053478
  • 博文数量: 2759
  • 博客积分: 1021
  • 博客等级: 中士
  • 技术积分: 4091
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-11 14:14
文章分类

全部博文(2759)

文章存档

2019年(1)

2017年(84)

2016年(196)

2015年(204)

2014年(636)

2013年(1176)

2012年(463)

分类:

2012-12-20 13:50:50

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. }

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