Bubble sort complete with optimization.