Sorting algorithms/Bubble sort: Difference between revisions
Content deleted Content added
Line 385: | Line 385: | ||
RAIterator end) { |
RAIterator end) { |
||
using std::swap; |
using std::swap; |
||
bool changed = true; |
|||
while (begin != end-- && changed) { |
|||
changed = false; |
|||
for (auto i = begin; i != end; ++i) { |
for (auto i = begin; i != end; ++i) { |
||
if (*(i + 1) < *i) { |
if (*(i + 1) < *i) { |
||
swap(*i, *(i + 1)); |
swap(*i, *(i + 1)); |
||
changed = true; |
|||
} |
} |
||
} |
} |