設a[0:n-1]是已排好序的數組.請改寫二分搜索算法,使得當被搜索元素x不在數組中時,返回小於x的最大元素...

主要是對二分法的改寫,若是熟悉二分法就很是簡單。數組 具體代碼以下:code #include<stdio.h> #include<stdlib.h> //二分法查找 int search(int a[],int length, int x) //a是搜索數組,x爲搜索元素 { int i = 0, j = 0; int detection = -1;//標誌位 int top
相關文章
相關標籤/搜索