1. Edit textbox2
Multiline : True
ScrollBars : Vertical
2. Edit label1
Text : Jumlah Data
3. Edit button1
Text : Sort By Shell
Kemudian klik 2 kali pada textbox1. Jika sudah, masukkan koding d bawah ini :
Public Class Form1
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 + 1)
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 ShellSort()
Dim G, F As Integer
Dim C As Double
G = N \ 2
While G > 0
Do
F = 0
For X = 1 To N - G
If AR(X) > AR(X + G) Then
C = AR(X)
AR(X) = AR(X + G)
AR(X + G) = C
F = 1
End If
Next X
Loop Until F = 0
G = G \ 2
End While
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call ShellSort()
T = ""
For X = 1 To N
T += Trim(Str(AR(X))) & " "
Next X
TextBox2.Text = T
End Sub
End Class
0 komentar:
Posting Komentar