折半查找
来源:互联网 发布:photoshop for mac下载 编辑:程序博客网 时间:2024/04/29 20:44
#include "stdafx.h"#include<iostream>#include <time.h>using namespace std;#pragma warning(disable:4996)void HalfSearch(int num[], int left, int right, int nData){int Mid = (right + left) / 2;if (left == right){return;}if (num[Mid] == nData){printf("%d\n", Mid);return;}if (num[Mid] >= nData){HalfSearch(num, left, Mid, nData);}else{HalfSearch(num, Mid, right, nData);}}int _tmain(int argc, _TCHAR* argv[]){int num[9] = {1, 6, 9 , 12, 18, 20, 40, 55, 61};HalfSearch(num, 0, 9, 12);return 0;}二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好;其缺点是要求待查表为有序表,且插入删除困难。因此,折半查找方法适用于不经常变动而查找频繁的有序列表
0 0
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- Android Gradle Plugin指南(二)——基本项目 - 琴弦第七的专栏 - 博客频道 - CSDN.NET
- POJ 2945 Find the Clones
- UVA 401
- BFS-POJ-3278-Catch That Cow
- CSS盒子模型
- 折半查找
- LeetCode---(160)Intersection of Two Linked Lists判断两个链表是否相交
- vector 四
- LeetCode(94) Binary Tree Inorder Traversal
- sift是图像匹配的非常经典的算法
- shape layer-list selector使用
- 【BMI指数计算器V2.0】项目实战
- iostream
- DFS-POJ-1321-棋盘问题