Function name: Finetab binary lookup algorithm-> check the temperature table//function function: Find the data in the table in the corresponding location table data from large to small//Entry parameters: Table address, table length, Data/exit parameter to find: no//return value: Position of data in table//***************************************/int finetab (int *a,int tablong,int data)/check
Table data is sorted from large to small {int st,ed,m;
int i;
st = 0; Initialize the number of queries to be the first ed = TabLong-1;//The last number i = 0;
if (data >= a[st]) return St;
else if (data < a[ed]) return ed;
while (St < ed) {m = (st+ed) >>1//binary to query intermediate value if (data = = A[m]) break;
if (Data < a[m] && data > A[m+1]) break;
if (Data > A[m]) ed = m;
else St = m;
if (++i > Tablong) break;
} if (St > ed) return 0;
return m; //*************************************//Function name: Finetab binary lookup algorithm-> check the temperature table//function function: Find the data in the table corresponding to the location table data from small to large sort//Entry parameters: Table address, table Length, data//exit parameters to find: no//return value: The position of the data in the table//***************************************/int fine1tab (int *a,int tablong,int dat
a) {int st,ed,m;
int i; St = 0;//Initialize the number of queries to be the first ed = TabLong-1;//The last number i = 0;
if (data <= a[st]) return ST//is less than or equal to the first number, the query value is 0, that is, the first number else if (data >= a[ed]) return ed;/is greater than or equal to the last number, and the query is the last number while (St < ed)//loop query {m = (st+ed) >>1//binary to query intermediate value if (data = = A[m]) break;/Just the value to query, end query if (DAT A > A[m-1] && data < a[m]) break;//data between the last value between intermediate and intermediate values, the end query if (data < a[m]) ed = m;//data is less than the current intermediate value, update the most After the range value else St = m;
Data is greater than the current intermediate value, the update start range value if (++i > Tablong)//prevent overflow break;
} if (St > ed) return 0;
return m;
}