copy(v.begin(), v.end(), iter);
cout ‹‹ endl;
return 0;
}
stblsrt2.cpp
#include ‹stl.h›
#include ‹iostream.h›
#include ‹string.h›
bool string_less(const char* a_, const char* b_) {
return ::strcmp(a_, b_) ‹ 0 ? 1 : 0;
}
char* letters[6] = {'bb', 'aa', 'll', 'dd', 'qq', 'cc'};
int main() {
stable_sort(letters, letters + 6, string_less);
for (int i = 0; i ‹ 6; i++) cout ‹‹ letters[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
nextprm1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main() {
vector‹int› v1(3);
iota(v1.begin(), v1.end(), 0);
ostream_iterator‹int› iter(cout, ' ');
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
for (int i = 0; i ‹ 9; i++) {
next_permutation(v1.begin(), v1.end());
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
}
return 0;
}
prevprm1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main() {
vector‹int› v1(3);
iota(v1.begin(), v1.end(), 0);
ostream_iterator‹int› iter(cout, ' ');
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
for (int i = 0; i ‹ 9; i++) {
prev_permutation(v1.begin(), v1.end());
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
}
return 0;
}
rndshuf1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main() {
vector‹int› v1(10);
iota(v1.begin(), v1.end(), 0);
ostream_iterator‹int› iter(cout, ' ');
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
for (int i = 0; i ‹ 3; i++) {
random_shuffle(v1.begin(), v1.end());
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
}
return 0;
}
ptrbinf1.cpp
#include ‹iostream.h›
#include ‹stl.h›
int sum(int x_, int y_) {
return x_ + y_;