Bubble sort is easy to implement and it is fast enough when you have small data sets.
Bubble sort is fast enough when your set is almost sorted (e.g. one or several elements are not in the correct positions), in this case you better to interlace traverses from 0-index to n-index and from n-index to 0-index.
Using C++ it can be implemented in the following way:
void bubbleSort(vector& v) { // sort in ascending order
bool go = true;
while (go) {
go = false;
for (int i = 0; i+1 < v.size(); ++i)
if (v[i] > v[i+1]) {
swap(v[i], v[j]);
go = true;
}
for (int i = (int)v.size()-1; i > 0; --i)
if (v[i-1] > v[i]) {
swap(v[i-1], v[i]);
go = true;
}
}
}
It can be good if swap of two adjacent items is chip and swap of arbitrary items is expensive.
Donald Knuth, in his famous "The Art of Computer Programming", concluded that "the bubble sort seems to have nothing to recommend it, except a catchy name and the fact that it leads to some interesting theoretical problems".
Since this algorithm is easy to implement it is easy to support, and it is important in real application life cycle to reduce effort for support.