斐波那契查找
来源:互联网 发布:深泉学院知乎 编辑:程序博客网 时间:2024/05/17 04:52
基于二分法 此算法依靠斐波那契数列 来跳转比较位置 在玩数位板所以有了手写图 单步骤原理如下
---C语言实现
#include<stdio.h>#include<stdlib.h>#define RETURN_FAIL -1//斐波那契查找int FibonacciSearch(int *Src_int,int Src_len,int SearchNum){int LowIndex;int HighIndex;int MidIndex;int *phead = NULL;int count;int loop;int LastNum;int LastLastNum;int CurrentNum;if(Src_int == NULL || Src_len <= 0)return RETURN_FAIL;//创建斐波那契数列LastNum = 1;LastLastNum = 1;CurrentNum = LastNum+LastLastNum;count = 3;while(Src_len >= CurrentNum){LastLastNum = LastNum;LastNum = CurrentNum;CurrentNum = LastNum+LastLastNum;count++;}phead = (int *)malloc(sizeof(int)*(count));LastNum = 1;LastLastNum = 1;phead[0] = 0;phead[1] = LastNum;phead[2] = LastLastNum;for(loop = 3;loop<=count;loop++){phead[loop] = LastNum+LastLastNum;LastLastNum = LastNum;LastNum = phead[loop];}//查找LowIndex = 1;HighIndex = Src_len;while(LowIndex <= HighIndex){MidIndex = LowIndex+phead[count-1]-1;if(MidIndex >= Src_len)MidIndex = Src_len-1;if(SearchNum == Src_int[MidIndex]){return MidIndex;}else if(SearchNum > Src_int[MidIndex]){LowIndex = MidIndex+1;count-= 2; }else{HighIndex = MidIndex-1;count-= 1; }}return RETURN_FAIL;}int main(){int result;int test[] = {0,1,8,16,23,35,47,59,78,88,99,123,234,555};result = FibonacciSearch(test,sizeof(test)/sizeof(test[0]),555);printf("%d\n",result);system("pause");return 0;}
0 0
- 查找-斐波那契查找
- 算法--查找--斐波那契查找
- 斐波那契查找
- 斐波那契查找
- 斐波那契查找
- 斐波那契查找
- 斐波那契查找
- 斐波那契查找
- 斐波那契查找
- 斐波那契查找
- 斐波那契查找
- 斐波那契查找
- 斐波那契查找
- 斐波那契查找
- 斐波那契查找
- 斐波那契查找
- 二分查找,插值查找,斐波那契查找
- 查找--顺序查找,二分法,斐波那契查找
- Sublime text 2/3 中 Package Control 的安装与使用方法
- hello word
- 打印字母菱形
- VLC播放 RTP流的 音频 视频的 sdp描述文件
- sql
- 斐波那契查找
- 常用的函数汇总(自定义函数)
- Android ConstraintLayout详解
- 二进制补码
- 手把手教你webpack、react和node.js环境配置(上篇)
- cocos2d 跨平台原理 以及android.mk编译的入口
- 个人总结-布局的使用(附加部分其他知识总结)
- 青鸟影院售票系统
- Python 中的var_dump, 对象打印