Test
2012-02-24 05:29
134 查看
/** * Will receive a heap integer array and return the height of the subtree rooted * at the 3rd smallest value * * @param heap * 0-based integer array * @return Height of the subtree rooted at the 3rd smallest value */ public int subTreeHeight(int[] heap) { // TODO You must implement this method if(!isHeap(heap)) // Test if the tested Heap is a valid Heap return -1; else if(heap.length < 3 || heap[1] == -1 || heap[2] == -1) // while the elements in Heap less than 3, there is no third smallest element return -1; else if(heap[1] <= heap[2]) { if(heap[3] != -1 && heap[3] < heap[2]) return getSubHeight(heap, 3); else if(heap[4] != -1 && (heap[4] < heap[3] && heap[4] < heap[2])) return getSubHeight(heap, 4); else if(heap[4] != -1 && (heap[3] <= heap[4] && heap[3] < heap[2])) return getSubHeight(heap, 3); else return getSubHeight(heap, 2); } else { if(heap[5] != -1 && heap[5] < heap[1]) return getSubHeight(heap, 5); else if(heap[6] != -1 && (heap[6] < heap[5] && heap[6] < heap[1])) return getSubHeight(heap, 6); else if(heap[6] != -1 && (heap[5] <= heap[6] && heap[5] < heap[1])) return getSubHeight(heap, 5); else return getSubHeight(heap, 1); } } /** * @description get the height of subtree which rooted heap * @param int[] heap * @param int n * @return height of subtree */ private int getSubHeight(int[] heap, int n) { int heigth = 0; while((NUM * n + 1) < heap.length) { if(heap[NUM*n +1] != -1) heigth++; n = NUM * n + 1; } return heigth; }
相关文章推荐
- test notation from testNG
- python单元测试unittest
- faster rcnn test demo ---repaired for video input and save the image, label, score et al. into .mat format
- python接口自动化测试(六)-unittest-单个用例管理
- 第一篇,TEST
- $ sqlplus oe/oe@//myserver.mydomain:1521/testdb
- KING_U3D学习之Unity Test Tools(二)_小实例实践
- 9.11 test
- A Practitioner's Guide to Software Test Design
- Test Driven Development
- test
- pycharm 解除默认unittest模式
- test
- 《xUnit Test Patterns》学习笔记7(完) - 总结
- test
- 关于自动化测试环境的集成(Jenkins+RobotFramework+TestLink+SVN)
- 将web窗体页文件(test.aspx)转换成用户控件文件(test.ascx)
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之六 - 运行参数
- ora-01950 no privileges on tablespasce TESTDATA 错误解决办法
- 顺序表Test1