VB.Net的冒泡排序算法

    Public Sub BubbleSort(ByVal R As Integer())
        Dim i, j, temp As Integer
        '交换标志
        Dim exchange As Boolean
        For i = 0 To R.Length - 1
            '本趟排序开始前,交换标志应为假
            exchange = False
            For j = R.Length - 2 To 0 Step -1
                '交换条件
                If R(j + 1) < R(j) Then
                    temp = R(j + 1)
                    R(j + 1) = R(j)
                    R(j) = temp
                    '发生了交换,故将交换标志置为真
                    exchange = True
                End If
            Next
            '本趟排序未发生交换,提前终止算法
            If Not exchange Then
                Exit For
            End If
        Next
    End Sub