| | | | | |

Generic Max

template <class I>
I g_max_element (I beg, I end)
{
  if (beg == end)
    return end;
  I max (beg);
  while (++beg != end)
    if (*max < *beg)
      max = beg;
  return max;
}

// usage:
Litr = g_max_element (L.Begin(), L.End()) // location of max element in List L
Vitr = g_max_element (V.Begin(), V.End()) // location of max element in Vector V
Ditr = g_max_element (D.Begin(), D.End()) // location of max element in Deque D
Aitr = g_max_element (A, A + size)        // location of max element in array A

| | Top of Page | 8. Generic Algorithms - 4 of 12