C++冒泡法排序算法演示代码
#include <algorithm> template<typename Iterator> void bubbleSort(Iterator first, Iterator last) { Iterator i, j; for (i = first; i != last; ++i) for (j = first; j < i; ++j) if (*i < *j) std::iter_swap(i, j); } template<typename Iterator, class StrictWeakOrdering> void bubbleSort(Iterator first, Iterator last, StrictWeakOrdering compare) { Iterator i, j; for (i = first; i != last; ++i) for (j = first; j < i; ++j) if (compare(*i, *j)) std::iter_swap(i, j); }