Sorting algorithms/Bubble sort: Difference between revisions

m
Line 377:
 
=={{header|C++}}==
Uses C++11. Compile with
g++ -std=c++11 bubble.cpp
<lang cpp>#include <algorithm>
#include <iostream>
Line 384 ⟶ 386:
template <typename RAIterator> void bubble_sort(RAIterator begin,
RAIterator end) {
bool changedswapped = true;
using std::swap;
while (begin != end-- && changedswapped) {
bool changed = true;
changedswapped = false;
while (begin != end-- && changed) {
changed = false;
for (auto i = begin; i != end; ++i) {
if (*(i + 1) < *i) {
swapstd::iter_swap(*i, *(i + 1));
changedswapped = true;
}
}