Track the number of outer iterations to reduce the number of inner iterations. The last few elements will always be sorted anyway.
Track the number of outer iterations to reduce the number of inner iterations. The last few elements will always be sorted anyway.