fbpx

C++: Bubble Sort

Bjarne-stroustrup
 

#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); // or std::swap(*i, *j);
		}
	}
}

SOURCE