swap()

  1. template <class T> void swap ( T& a, T& b )
  2. {
  3. T c(a); a=b; b=c;
  4. }

reverse()

  1. template <class BidirectionalIterator>
  2. void reverse (BidirectionalIterator first, BidirectionalIterator last)
  3. {
  4. while ((first!=last)&&(first!=--last)) {
  5. std::iter_swap (first,last);
  6. ++first;
  7. }
  8. }

sort()

  1. template <class RandomAccessIterator, class Compare>
  2. void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp);
  1. bool bigger(student a, student b)
  2. {
  3. return (a.score > b.score);
  4. }
  5. struct student{
  6. string name;
  7. char gender;
  8. int score;
  9. };
  10. vector<student> v;
  11. sort(v.begin(), v.end(), bigger);

unique()

从输入序列中“删除”所有相邻的重复元素,并将这些元素移到最后,返回一个迭代器指针,指针指向的正是最后那些重复元素的第一个元素

prev_permutation()/next_permutation()

  1. template bool prev_permutation (BidirectionalIterator first, BidirectionalIterator last );
  2. parameters:
  3. first, last : Bidirectional iterators to the initial and final positions of the sequence. The range
  4. used is [first, last), which contains all the
  5. elements between first and last, including
  6. the element pointed by first but not the element
  7. pointed by last.
  8. return value:
  9. true : if the function could rearrange
  10. the object as a lexicographicaly smaller permutation.
  11. Otherwise, the function returns false to indicate that
  12. the arrangement is not less than the previous, but the largest possible (sorted in descending order).