文章标题
来源:互联网 发布:数据存储安全 编辑:程序博客网 时间:2024/06/11 10:26
面试题
1、请实现二分查找法
答:
#include <iostream>using namespace std;const int g_nSize = 32;int FindValuePos(int (&arry)[g_nSize], int nValue){ int nLeft = sizeof(arry) / sizeof(int) / 2; int nPos = nLeft; while (nLeft > 0) { nLeft = nLeft - nLeft / 2; if (nValue < arry[nPos]) { nPos -= nLeft; } else if (nValue > arry[nPos]) { nPos += nLeft; } else { return nPos; } } return -1;}int main(){ int arry[g_nSize]; for(int i = 0; i < g_nSize; i++) { arry[i] = i * 100; } cout << "Pos:" << FindValuePos(arry, 0) << endl; system("pause"); return 0;}
阅读全文
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 常见的聚类算法
- unicode和utf8的区别
- 个人总结45
- 第五届光电信息协会竞赛——XXXX
- php中的布尔值
- 文章标题
- 设计模式之禅16
- day7_类的重要方法和socket基础
- 菱形和水仙花数
- python 3.x 字典的11种方法
- Codeforces --- Mahmoud and Ehab and the MEX
- 深入了解PHP【生命周期】
- Item 11:在赋值操作符中处理自我赋值【effective C++读书笔记】
- VisualSVN Server v3.7