Różnice między wybraną wersją a wersją aktualną.
Both sides previous revision Previous revision Next revision | Previous revision | ||
min_element_max_element [2008/12/11 00:14] kkukolow |
min_element_max_element [2008/12/11 00:21] (aktualna) kkukolow |
||
---|---|---|---|
Linia 36: | Linia 36: | ||
<code cpp> | <code cpp> | ||
template <class ForwardIterator> | template <class ForwardIterator> | ||
- | ForwardIterator max_element ( ForwardIterator first, ForwardIterator last ) | + | ForwardIterator min_element ( ForwardIterator first, ForwardIterator last ) |
{ | { | ||
- | ForwardIterator largest = first; | + | ForwardIterator lowest= first; |
if (first==last) return last; | if (first==last) return last; | ||
while (++first!=last) | while (++first!=last) | ||
- | if (*largest<*first) // or: if (comp(*largest,*lowest)) for the comp version | + | if (*first<*lowest) // or: if (comp(*first,*lowest)) for the comp version |
- | largest=first; | + | lowest=first; |
- | return largest; | + | return lowest; |
} | } | ||
</code> | </code> | ||
Linia 61: | Linia 61: | ||
===== Złożoność ===== | ===== Złożoność ===== | ||
- | Liniowa: wywołuje funkcję op i dokonuje przyporządkowania zwracanej przez nią wartości co najwyżej tylokrotnie, ile jest elementów w zakresie [first1, last1) | + | Liniowa: wykonuje operacje porównania n-1 razy, gdzie n to ilość elementów w zakresie |