Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write the complete C code of Fibonacci search algorithm

Shulou Source: shulou.com Published: 2022-06-03 05:41:57 11月19日 Update

This article will explain in detail how to write the complete C code of Fibonacci search algorithm, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

/ * Fibonacci search method * / # include # include int Fib (int k) {if (1 = = k | | 2 = = k) return 1; else return Fib (KMI 1) + Fib (KMUE 2);} int FibSearch (int * a, int n, int key) {int k = 1; int nFib; int * b; int low, mid, high While (Fib (k)

< n ) //找到Fib[k] k++; nFib = Fib(k); b = (int *)realloc( a, sizeof(int)*nFib ); //扩充数组的大小 for( int i=n; i key ) { k = k - 1; high = mid; } if( b[mid] < key ) { k = k-2; low = mid+1; } if( b[mid] == key ) { if( mid >

= nmur1 & & mid

Tags: Code element array algorithm success two content size article more knowledge article scope input good ordered number location key keyword Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Huawei Shulou Information Linux Shulou Technology