Exercise1.1.22
2016-01-11 20:26
375 查看
package chapterone; public class Exercise1_1_22 { public static int rank(int key, int[] array) { return rank(key, array, 0, array.length - 1, 0); } public static int rank(int key, int[] array, int low, int high, int indent) { if (low > high) { return -1; } int mid = (low + high) / 2; System.out.println(repeat(4 * indent, ' ') + low + high); if (key > array[mid]) { return rank(key, array, mid + 1, high, ++indent); } else if (key < array[mid]) { return rank(key, array, low, mid - 1, ++indent); } else { return mid; } } public static String repeat(int n, char c) { String s = ""; for (int i = 0; i < n; i++) { s += c; } return s; } public static void main(String[] args) { int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; System.out.println(rank(3, array)); } }
相关文章推荐
- HDU 2089 不要62(挖个坑=-=)
- Office365-----Skype for business
- Yii的CSRF验证
- WebFrontEndStack
- mysql copy data from table to another
- python 获取探针页面,自动查询公司出口
- [Leetcode] 1.Two Sum @python
- iOS_视图控制对象生命周期以及区别和用途
- bind--C++11
- 原来mysql只能显示1000条数据
- 颜如玉——一月第2周
- 高性能Mysql主从架构的复制原理及配置详解
- Struts2的Convention插件
- [开发笔记]-未找到与约束ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryService...匹配的导出【转载自:酷小孩】
- IOS不用AutoLayout也能实现自己主动布局的类(3)----MyRelativeLayout横空出世
- SQL_2_查询Select语句的使用
- quick-cocos中定时器的使用
- EM 算法的推导和解释
- [Noi2015]品酒大会|后缀数组|并查集
- ActiveX 暴漏你全部信息的可怕的插件!