2012年11月17日
总想提笔写点什么,却不知道该怎样记录这几个月的生活。满脑的思绪却无从下笔,只是感觉找工作也不是自己想的那么容易。看着一起找工作的人都找到了,就自己没有找到合适的,就慢慢的开始怀疑自己,对生活和未来丧失信心。不过还好懂得,人最不能放弃的就是希望,好多事情尽了自己最大的努力就好。
1
package com.test2;
2
3
public class Demo2
{
4
5
/** *//**
6
* @param args
7
*/
8
9
public static int search(int[] arrays, int target)
{
10
11
int start = 0;
12
int end = arrays.length - 1;
13
int pos;
14
while (start <= end)
{
15
pos = (start + end) / 2;
16
if (arrays[pos] == target)
{
17
return pos;
18
} else if (arrays[pos] > target)
{// 如果数组中间的数大于目标,则将end的位置变成数组中间位置-1的位置
19
end = pos - 1;
20
} else
{
21
start = pos + 1;// 如果数组中间的数小于目标,则将start的位置变成数组中间位置+1的位置
22
}
23
}
24
return -1; // 若没有查找到,则返回-1
25
}
26
27
public static void main(String[] args)
{
28
int[] arrays =
{ 2, 3, 28, 39, 59, 288, 322, 324, 2323 };
29
System.out.println(search(arrays, 28));
30
System.out.println(search(arrays, 322));
31
System.out.println(search(arrays, 59));
32
System.out.println(search(arrays, 288));
33
}
34
35
}
36