C#库:冒泡算法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public int[] SortInt(int[] R)
{
    for (int i = R.Length - 1; i >= 0; i--)
    {
        for (int n = 0; n < i; n++)
        {
            if (R[n] > R[n + 1])
            {
                int temp;
                temp = R[n];
                R[n] = R[n + 1];
                R[n + 1] = temp;
            }
        }
    }
 
    return R;
}