折半查找
来源:互联网 发布:制作图表的软件 编辑:程序博客网 时间:2024/05/29 08:49
static void Main(string[] args)
{
int[] data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
int position = Search(data,12, 12);
Console.WriteLine(position);
Console.ReadKey();
{
int[] data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
int position = Search(data,12, 12);
Console.WriteLine(position);
Console.ReadKey();
}
/// <summary>
///
/// </summary>
/// <param name="data">数据</param>
/// <param name="key">要找找的数据</param>
/// <param name="lenth">数组的长度</param>
/// <returns></returns>
public static int Search(int[] data, int key, int lenth)
{
int index = lenth/2;
if (data[index] < key)
{
return Search(data, key, index + data.Length);
}
else if(data[index] > key)
{
return Search(data, key, index +1);
}
else if(data[index]==key)
{
return index;
}
return -1;
}
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 禁止虚拟机(Windows)与主机时间同步(VM & Virtualbox & Virtual PC)
- 如何快速的学习并使用一门语言工作-2(原创)
- difference between SIM unlock and rooting phone
- IOS中的block
- 解决有关GIS点选重叠点的问题
- 折半查找
- Boost中的lambda
- xcode5 新特性
- CSS技巧及常见问题列表
- 【专题】KMP
- android EditText 隐藏系统键盘 保留光标
- 怎样删除C++中listcontrol中的一项或多项
- 主流HTML5游戏框架的分析和对比(Construct2、ImpactJS、CreateJS、Cocos2d-html5……) .
- 2013-09-29 创建sqlite