StoneHaos

Untitled

Mar 17th, 2021 (edited)
166
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int Interpol(int[] arr, int elem) {
  2.     int l = 0, r = arr.Length - 1;
  3.     int m;
  4.     while (arr[l] <= elem && arr[r] >= elem) {
  5.         m = Convert.ToInt32( l + ((1.0 * r - l) * (elem - arr[l])) / (arr[r] - arr[l]));
  6.         if (arr[m] < elem) l = m + 1;
  7.         else if (arr[m] > elem) r = m - 1;
  8.         else return m;
  9.     }
  10.     if (arr[l] == elem) return l;
  11.     else return -1;
  12.  
  13. }
RAW Paste Data