#include<iostream> using namespace std; int search_abs_min(int *, int ); void main(){ int array[]={-3,0}; cout<<search_abs_min(array,sizeof(array)/sizeof(array[0]))<<endl; system("pause"); } int search_abs_min(int* array, int len){ if(array == NULL || len<=0) return -1; int low=0, high=len-1; int mid; while(low<high){ if(high - low == 1) return (abs(array[low]) < abs(array[high])) ? abs(array[low]) : abs(array[high]); mid=low + ((high-low)>>1); if(array[mid] > 0){ if(array[mid-1] <= 0) return (abs(array[mid]) < abs(array[mid-1])) ? abs(array[mid]) : abs(array[mid-1]); else high=mid; } else if(array[mid] < 0){ if(array[mid+1] >= 0) return (abs(array[mid]) < abs(array[mid-1])) ? abs(array[mid]) : abs(array[mid-1]); else low=mid; } else return 0; } return array[low]; }