Last active
August 29, 2015 13:56
-
-
Save shoooe/9202284 to your computer and use it in GitHub Desktop.
Implementation of bubble sort in C++ as an exercise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <algorithm> | |
template<typename IT> | |
void bubble_sort(IT begin, IT end) { | |
while (true) { | |
bool c = false; // changed? | |
for (IT i = begin; i != end-1; i = i+1) { | |
if (*i > *(i+1)) { | |
std::iter_swap(i, i+1); | |
c = true; | |
} | |
} | |
if (c == false) return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment