};
int array[3] = {1, 2, 3};
int main() {
int* p = find_if(array, array + 3, unary_negate‹odd›(odd()));
if (p != array + 3)
cout ‹‹ *p ‹‹ endl;
return 0;
}
alg4.cpp
#include ‹iostream.h›
#include ‹stl.h›
int main() {
vector‹int› years;
years.push_back(1962);
years.push_back(1992);
years.push_back(2001);
years.push_back(1999);
sort(years.begin(), years.end());
vector‹int›::iterator i;
for (i = years.begin(); i!= years.end(); i++)
cout ‹‹ *i ‹‹ endl;
return 0;
}
countif1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int odd(int a_) {
return a_ % 2;
}
int main() {
vector‹int› numbers(100);
for (int i = 0; i ‹ 100; i++) numbers[i] = i % 3;
int elements = 0;
count_if(numbers.begin(), numbers.end(), odd, elements);
cout ‹‹ 'Found ' ‹‹ elements ‹‹ ' odd elements.' ‹‹ endl;
return 0;
}
lwrbnd1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main() {
vector‹int› v1(20);
for (int i = 0; i ‹ v1.size(); i++) {
v1[i] = i/4;
cout ‹‹ v1[i] ‹‹ ' ';
}
int* location = lower_bound(v1.begin(), v1.end(), 3);
cout ‹‹ '
3 can be inserted at index: ' ‹‹ (location - v1.begin()) ‹‹ endl;
return 0;
}
lexcmp1.cpp
#include ‹stl.h›
#include ‹iostream.h›
const unsigned size = 6;
char n1[size] = 'shoe';
char n2[size] = 'shine';
int main() {
bool before = lexicographical_compare(n1, n1 + size, n2, n2 + size);
if (before) cout ‹‹ n1 ‹‹ ' is before ' ‹‹ n2 ‹‹ endl;
else cout ‹‹ n2 ‹‹ ' is before ' ‹‹ n1 ‹‹ endl;
return 0;
}
copyb.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main() {
vector‹int› v1(10);
for (int i = 0; i ‹ v1.size(); i++) v1[i] = i;
vector‹int› v2(v1.size());
copy_backward(v1.begin(), v1.end(), v2.end());