Różnice między wybraną wersją a wersją aktualną.
Both sides previous revision Previous revision Next revision | Previous revision | ||
count_count_if [2008/12/11 18:18] abartcza |
count_count_if [2008/12/12 00:03] abartcza |
||
---|---|---|---|
Linia 8: | Linia 8: | ||
===== Opis algorytmu count ===== | ===== Opis algorytmu count ===== | ||
- | === Deklaracja algorytmu count === | + | === Definicja algorytmu count === |
<code cpp> template <class InputIterator, class T> | <code cpp> template <class InputIterator, class T> | ||
ptrdiff_t count ( InputIterator first, InputIterator last, const T& value ) | ptrdiff_t count ( InputIterator first, InputIterator last, const T& value ) | ||
Linia 74: | Linia 74: | ||
===== Opis algorytmu count_if ===== | ===== Opis algorytmu count_if ===== | ||
- | === Deklaracja algorytmu count_if === | + | === Definicja algorytmu count_if === |
<code cpp> template <class InputIterator, class Predicate> | <code cpp> template <class InputIterator, class Predicate> | ||
ptrdiff_t count_if ( InputIterator first, InputIterator last, Predicate pred ) | ptrdiff_t count_if ( InputIterator first, InputIterator last, Predicate pred ) | ||
Linia 98: | Linia 98: | ||
=== Przykład użycia algorytmu count_if=== | === Przykład użycia algorytmu count_if=== | ||
- | <code cpp> // funkcja wykrywająca polskie imiona kobiet | + | <code cpp> // funkcja wykrywająca polskie imiona kobiet |
bool NameWoman(const string& str) { | bool NameWoman(const string& str) { | ||
return (str[str.size()-1] == 'a' || str[str.size()-1] == 'A'); | return (str[str.size()-1] == 'a' || str[str.size()-1] == 'A'); | ||
Linia 115: | Linia 115: | ||
int main() { | int main() { | ||
- | typedef vector<string> VectorString; | + | // tutaj odpowiednie deklaracje ... |
- | + | ||
- | typedef VectorString::iterator VectorStringIt; | + | |
- | + | ||
- | // wektor imion | + | |
- | VectorString vect; | + | |
- | + | ||
- | // iteratory wskazujace na wektor imion vect | + | |
- | VectorStringIt start, end; | + | |
- | + | ||
- | // zmienna zawierająca liczbę elementów pasująca do danego wzroca | + | |
- | ptrdiff_t result; | + | |
- | + | ||
// przykladowy napis ktory jest wypelniony polskimi imionami, odzielony znakami | // przykladowy napis ktory jest wypelniony polskimi imionami, odzielony znakami | ||
// które nie są literami alfabetu (separatorami). W imionach nie należy wstawiać | // które nie są literami alfabetu (separatorami). W imionach nie należy wstawiać | ||
Linia 167: | Linia 156: | ||
===== Przykładowy program wykorzystujący algorytmy count i count_if ===== | ===== Przykładowy program wykorzystujący algorytmy count i count_if ===== | ||
- | {{count_count_if.cpp}} | + | {{count_count_if2.cpp}} |
--- //[[master.bartczak@gmail.com|Adam Bartczak 5TIZ]]// | --- //[[master.bartczak@gmail.com|Adam Bartczak 5TIZ]]// |