After taking multiple tests, I got a bubble Algorithm for several times, one for C # and the other for javascript.
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;