| | | | | |

Generic Find (Sequential Search)

template <class I, typename T>
I g_find (I beg, I end, const T& t)
// classic sequential search
{
  for ( ; beg != end; ++beg)
    if (t == *beg)
      return beg;
  return end;
}

// usage:
Litr = g_find (L.Begin(), L.End(), t) // location of t in TList L
Vitr = g_find (V.Begin(), V.End(), t) // location of t in TVector V
Ditr = g_find (D.Begin(), D.End(), t) // location of t in TDeque D
Aitr = g_find (A, A + size, t)        // location of t in array A
// note that return of End() iterator (invalid iterator) means "not found"

| | Top of Page | 7. Generic Algorithms - 3 of 12