Kamis, 15 September 2011

Bubble 01




Public Class Form1
    Dim T As String
    Dim AR(), N As Integer

    Sub BUBBLE01()
        Dim X, Y, C As Byte
        For X = 1 To N - 1
            For Y = 1 To N - X
                If AR(Y) > AR(Y + 1) Then
                    C = AR(Y)
                    AR(Y) = AR(Y + 1)
                    AR(Y + 1) = C
                End If

            Next
        Next
    End Sub

    Private Sub TextBox2_KeyPress(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.KeyPressEventArgs) _
    Handles TextBox2.KeyPress
        Dim R As Integer
        If e.KeyChar = Chr(13) Then
            N = Val(TextBox2.Text)
            ReDim AR(N)
            T = ""
            For I As Byte = 1 To N
                R = Int(Rnd() * 99) + 100
                AR(I) = R
                T += Trim(Str(R)) & "  "
            Next
            TextBox1.Text = T
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        BUBBLE01()
        T = ""
        For X = 1 To N
            T += Trim(Str(AR(X))) & "  "
        Next
        TextBox1.Text = T
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class
 


Tidak ada komentar:

Posting Komentar