Dim T As String
Dim AR() As Integer, N As Integer
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim R As Integer
If e.KeyChar = Chr(13) Then
N = Val(TextBox1.Text)
ReDim AR(N)
T = ""
For I As Byte = 1 To N
R = Int(Rnd() * 899) + 100
AR(I) = R
T += Trim(Str(R)) + " "
Next
TextBox2.Text = T
End If
End Sub
Sub Bubble03()
Dim C, F, X, Y As Integer
Do
X = X + 1
F = 0
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
F = 1
End If
Next Y
Loop Until F = 0
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
BUBBLE03()
T = ""
For X = 1 To N
T += Trim(Str(AR(X))) & " "
Next
TextBox2.Text = T
End Sub
End Class
Tidak ada komentar:
Posting Komentar