Berikut saya memberikan contoh program dengan menggunakan Visual Basic untukprogram penggurutan Bubble Sort ini, yaitu :
buat tampilan seperti dibawah ini:
Komponen :
Textbox1 --> bil
Textbox2 --> n
Textbox3 --> hasil
Button1 --> nama nya tetap button1
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim bila() As String
Dim i As Integer
Dim temp As String
bila = Split(bil.Text, ",")
Dim j, batas As Integer
batas = n.Text
For i = 1 To batas
j = batas - 1
Do While j >= i
If Val(bila(j)) < Val(bila(j - 1)) Then
temp = bila(j)
bila(j) = bila(j - 1)
bila(j - 1) = temp
End If
j = j - 1
Loop
Next i
Hasil.Text = ""
For i = 0 To batas - 1
If i = 0 Then
hasil.Text = hasil.Text & bila(i)
Else
hasil.Text = hasil.Text & "," & bila(i)
End If
Next i
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
bil.Text = ""
hasil.Text = ""
n.Text = ""
End Sub
End Class
kemudian Debug program anda:
Tidak ada komentar:
Posting Komentar