コード例 #1
0
template<class T, class Tab> int search_in_ordered_vect(T x, const Tab & v) {
  if (!v.size_array())
    return -1;
  int i1=0;
  int i;
  int i2 = (int)v.size_array()-1;
  while (i1 != i2) {
    i = (i1+i2)/2;
    if (v[i] < x)
      i1=i+1;
    else
      i2=i;
  }
  if (v[i1] == x)
    return i1;
  return -1;
}
コード例 #2
0
static void retirer_doublons(Tab & tab, const T epsilon)
{
  int i = 0;
  int j;
  const int n = tab.size_array();
  T last_tab_i = -1e40;
  for (j = 0; j < n; j++) {
    const T x = tab[j];
    assert(x >= last_tab_i); // Array must be sorted
    if (x - last_tab_i > epsilon) {
      tab[i] = x;
      last_tab_i = x;
      i++;
    }
  }
  tab.resize_array(i);
}