Шрифт:
int main {
typedef multiset‹char*, less_s› mset;
mset s;
s.insert(names, names + 6);
for (mset::iterator i = s.begin; i!= s.end; i++) cout ‹‹ *i ‹‹ endl;
return 0;
}
ostmit.cpp
#include ‹iostream.h›
#include ‹stl.h›
int array[] = {1, 5, 2, 4};
int main {
char* string = "hello";
ostream_iterator‹char› it1(cout);
copy(string, string + 5, it1);
cout ‹‹ endl;
ostream_iterator‹int› it2(cout);
copy(array, array + 4, it2);
cout ‹‹ endl;
return 0;
}
ptrunf1.cpp
#include ‹iostream.h›
#include ‹stl.h›
bool even(int n_) {
return (n_ % 2) == 0;
}
int array[3] = {1, 2, 3};
int main {
int* p = find_if(array, array + 3, pointer_to_unary_function‹int, bool›(even));
if (p != array + 3) cout ‹‹ *p ‹‹ " is even" ‹‹ endl;
return 0;
}
func1.cpp
#include ‹iostream.h›
#include ‹stl.h›
bool bigger(int i_) {
return i_ › 3;
}
int main {
vector‹int› v;
v.push_back(4);
v.push_back(1);
v.push_back(5);
int n = 0;
count_if(v.begin, v.end, bigger, n);
cout ‹‹ "Number greater than 3 = " ‹‹ n ‹‹ endl;
return 0;
}
stblptn0.cpp
#include ‹stl.h›
#include ‹iostream.h›
bool less_10(int a_) {
return a_ ‹ 10 ? 1 : 0;
}
int numbers[6] = {10, 5, 11, 20, 6, -2};
int main {
stable_partition(numbers, numbers + 6, less_10);
for (int i = 0; i ‹ 6; i++) cout ‹‹ numbers[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
setunon0.cpp
#include ‹stl.h›
#include ‹iostream.h›
int v1[3] = {13, 18, 23};
int v2[4] = {10, 13, 17, 23};
int result[7] = {0, 0, 0, 0, 0, 0, 0};
int main {
set_union(v1, v1 + 3, v2, v2 + 4, result);
for (int i = 0; i ‹ 7; i++) cout ‹‹ result[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
mkheap1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int numbers[6] = {5, 10, 4, 13, 11, 19};
int main {
make_heap(numbers, numbers + 6, greater‹int›);
for (int i = 6; i ›= 1; i--) {
cout ‹‹ numbers[0] ‹‹ endl;
pop_heap(numbers, numbers + i, greater‹int›);
}
return 0;
}
setintr0.cpp
#include ‹stl.h›
#include ‹iostream.h›
int v1[3] = {13, 18, 23};