VB.net
Ini coddingnya.. :)
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 X, C, G, F As Integer
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
ShellSort()
T = ""
For X = 1 To N
T += Trim(Str(AR(X))) & " "
Next
TextBox2.Text = T
End Sub
End Class
Dan Inilah Outputnya..:)
No comments:
Post a Comment