This is my own written Fibonacci search algorithm, and other ideas on the web slightly different, special posted out:
1) There is no pre-stored Fibonacci array, the entire length of the search data can be changed;
2) The change of the mid index is dynamic, according to Fibonacci's fallback method;
#include <stdlib.h>
#include <stdio.h>
#define INF 32767
#define SIZE 92
int Feibinaci (int str[],int n,int key)
{
int F0 = 1;
int F1 = 1;
int temp;
int mid;
while (F1 < n)
{
temp = F1;
F1 = F1 + F0;
F0 = temp;
}
for (temp = n;temp < F1; temp + +)
{
Str[temp] = str[n-1];
}
MID = F0;
while (F1! = 0)
{
if (str[mid-1] = = key)//The setting of this place is very good, the reference is drawn;
{
if (mid >n)
return n;
Else
return mid;
}
else if (Str[mid-1] > key)
{
temp = F0;
F0 = f1-f0;
F1 = temp;
Mid = mid-(F1-F0);
}
Else
{
temp = F0;
F0 = f1-f0;
F1 = temp;
Mid = mid + (F1-F0);
}
}
return-1;
}
int main ()
{
int str[size];
int i;
int find_num;
int pos =-1;
for (i=1;i<size;i++)
{
Str[i-1] = i;
}
for (i=1;i<size;i++)
{
printf ("%d", str[i-1]);
}
printf ("\ n Please enter the number to look for:");
scanf ("%d", &find_num);
pos = Feibinaci (Str,size,find_num);
if (pos > 0)
{
printf ("Location of the number to find in:%d", POS);
}
Else
{
printf ("No related numbers found:%d", POS);
}
return 0;
}
Fibonacci Lookup algorithms-Data structures