For the second version, the one that takes three arguments:
Linear. At most
int main() {
int A[] = {2, 3, 4, 5, 6, 1};
const int N = sizeof(A) / sizeof(int);
cout << 'Initially: ';
copy (A, A+N, ostream_iterator<int>(cout, ' '));
cout << endl;
prev_permutation(A, A+N);
cout << 'After prev_permutation: ';
copy (A, A+N, ostream_iterator<int>(cout, ' '));
cout << endl;
next_permutation(A, A+N);
cout << 'After next_permutation: ';
copy (A, A+N, ostream_iterator<int>(cout, ' '));
cout << endl;
}
[1] If all of the elements in
[2] Note that the lexicographically greatest permutation is, by definition, sorted in nonascending order.
Generalized numeric algorithms
iota
Category: algorithms
Component type: function
template <class ForwardIterator, class T>
void iota(ForwardIterator first, ForwardIterator last, T value);
Defined in the standard header numeric, and in the nonstandard backward-compatibility header algo.h. This function is an SGI extension; it is not part of the C++ standard.
• If
Linear. Exactly
int main() {
vector<int> V(10);
iota(V.begin(), V.end(), 7);
copy(V.begin(), V.end(), ostream_iterator<int>(cout, ' '));
cout << endl;
}
[1] The name
accumulate
Category: algorithms
Component type: function
template <class InputIterator, class T>
T accumulate(InputIterator first, InputIterator last, T init);
template <class InputIterator, class T, class BinaryFunction>
T accumulate(InputIterator first, InputIterator last, T init, BinaryFunction binary_op);