Fibonacci Lookup algorithms-Data structures

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.