Skip to content

Bubble Sort

Bubble Sort

C++

1
2
3
4
5
6
7
8
9
template<typename It>
void BubbleSort(It begin, It end) {
    if (begin == end) return; //return if container is empty
    for (It i = end - 1; i != begin; i--) {
        for (It j = begin; j != i; j++) {
            if (*j > *(j + 1)) swap(*j, *(j+1));
        }
    }
}

Comments