optimize bubble sort: don't check elements after the last swap since they are sorted