After taking multiple tests, I got a bubble test. Algorithm C # is used to fill in the blanks at a time, and all the Javascript versions are written.
Although I made it through my understanding of the bubble method every time, it is more or less different from the standard mode. I found the C # bubble algorithm on the Internet, there is no sample. I carefully wrote a C # version against the algorithm mode, and the test was successful.
Together with the [bubble sort animation demo]
Public void bubblesort (INT [] r)
{
Int I, j, temp;
// Exchange flag
Bool exchange;
// Sort the R. Length-1 bits at most
For (I = 0; I <R. length; I ++)
{
// The exchange flag should be false before the sorting starts.
Exchange = false;
For (j = R. Length-2; j> = I; j --)
{
// Exchange conditions
If (R [J + 1] <R [J])
{
Temp = R [J + 1];
R [J + 1] = R [J];
R [J] = temp;
// If an exchange occurs, the exchange flag is set to true.
Exchange = true;
}
}
// This sort order is not exchanged and the algorithm is terminated in advance
If (! Exchange)
{
Break;
}
}
}