{
Int i, j, temp// exchange flag
Boolean exchange;
for(I = 0; I < length; I++) // Sort at most by R.Length- 1.
{
Exchange = false; //Before the sorting of this line starts, the exchange flag should be false.
for(j = R . Length-2; j & gt= I; j -)
{
if(R[j+ 1]& lt; R[j]) // exchange conditions
{
temp = R[j+ 1];
R[j+ 1]= R[j];
r[j]= temp;
Exchange = true; //Exchange has already occurred, so the exchange flag is set to true.
}
}
If (! Exchange)//There is no exchange in this sorting, and the algorithm is terminated early.
{
Break;
}
}
}