Pages

Kamis, 22 September 2011

BUBBLE SORT

Coding :
Dim R() As Integer
Dim N, P As Integer
Dim T As String

Sub DATA()
For I = 1 To N
    R(I) = Rnd * 899 + 100
Next I
End Sub

Sub VIEW()
T = ""
For I = 1 To N
T = T + Trim(Str(R(I))) + " "
Next I
End Sub
Sub BUBBLE01()
    For x = 1 To N - 1
    For Y = x + 1 To N
        If R(x) < R(Y) Then
            C = R(x)
            R(x) = R(Y)
            R(Y) = C
        End If
    Next Y
    Next x
End Sub
Sub BUBBLE02()
For x = 1 To N
For Y = 1 To N - x
If R(Y) > R(Y + 1) Then
    C = R(Y)
    R(Y) = R(Y + 1)
    R(Y + 1) = C
End If
Next Y
Next x
End Sub
Sub BUBBLE03()
x = 0
Do
F = 0
x = x + 1
For Y = 1 To N - x
    If R(Y) < R(Y + 1) Then
                C = R(Y)
                R(Y) = R(Y + 1)
                R(Y + 1) = C
                F = 1
                End If
Next Y
Loop Until F = 0
End Sub
Sub SELECTSORT()
For x = 1 To N - 1
    S = x
    For Y = x + 1 To N
        If R(S) > R(Y) Then S = Y
    Next Y
    If S <> x Then
        C = R(S)
        R(S) = R(x)
        R(x) = C
    End If
Next x
End Sub
Sub shellsort()
 G = N \ 2
While G > 0
 Do
 F = 0
 For x = 1 To N - G
 If R(x) > R(x + G) Then
  C = R(x)
  R(x) = R(x + G)
  R(x + G) = C
  F = 1
 End If
 Next
 Loop Until F = 0
 G = G \ 2
Wend
End Sub

Private Sub Command1_Click()
Select Case P
Case 1: BUBBLE01
Case 2: BUBBLE02
Case 3: BUBBLE03
Case 4: SELECTSORT
Case 5: shellsort
End Select
VIEW
Text2 = T
End Sub


Private Sub Option1_Click()
P = 4
End Sub

Private Sub Option2_Click()
P = 3
End Sub

Private Sub Option3_Click()
P = 2
End Sub

Private Sub Option4_Click()
P = 1
End Sub

Private Sub Option5_Click()
P = 5
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    N = Val(Text1)
    ReDim R(N)
    DATA
    VIEW
    Text2 = T
End If
End Sub
 

Tidak ada komentar:

Posting Komentar

Kamis, 22 September 2011

BUBBLE SORT

Coding :
Dim R() As Integer
Dim N, P As Integer
Dim T As String

Sub DATA()
For I = 1 To N
    R(I) = Rnd * 899 + 100
Next I
End Sub

Sub VIEW()
T = ""
For I = 1 To N
T = T + Trim(Str(R(I))) + " "
Next I
End Sub
Sub BUBBLE01()
    For x = 1 To N - 1
    For Y = x + 1 To N
        If R(x) < R(Y) Then
            C = R(x)
            R(x) = R(Y)
            R(Y) = C
        End If
    Next Y
    Next x
End Sub
Sub BUBBLE02()
For x = 1 To N
For Y = 1 To N - x
If R(Y) > R(Y + 1) Then
    C = R(Y)
    R(Y) = R(Y + 1)
    R(Y + 1) = C
End If
Next Y
Next x
End Sub
Sub BUBBLE03()
x = 0
Do
F = 0
x = x + 1
For Y = 1 To N - x
    If R(Y) < R(Y + 1) Then
                C = R(Y)
                R(Y) = R(Y + 1)
                R(Y + 1) = C
                F = 1
                End If
Next Y
Loop Until F = 0
End Sub
Sub SELECTSORT()
For x = 1 To N - 1
    S = x
    For Y = x + 1 To N
        If R(S) > R(Y) Then S = Y
    Next Y
    If S <> x Then
        C = R(S)
        R(S) = R(x)
        R(x) = C
    End If
Next x
End Sub
Sub shellsort()
 G = N \ 2
While G > 0
 Do
 F = 0
 For x = 1 To N - G
 If R(x) > R(x + G) Then
  C = R(x)
  R(x) = R(x + G)
  R(x + G) = C
  F = 1
 End If
 Next
 Loop Until F = 0
 G = G \ 2
Wend
End Sub

Private Sub Command1_Click()
Select Case P
Case 1: BUBBLE01
Case 2: BUBBLE02
Case 3: BUBBLE03
Case 4: SELECTSORT
Case 5: shellsort
End Select
VIEW
Text2 = T
End Sub


Private Sub Option1_Click()
P = 4
End Sub

Private Sub Option2_Click()
P = 3
End Sub

Private Sub Option3_Click()
P = 2
End Sub

Private Sub Option4_Click()
P = 1
End Sub

Private Sub Option5_Click()
P = 5
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    N = Val(Text1)
    ReDim R(N)
    DATA
    VIEW
    Text2 = T
End If
End Sub
 

0 komentar:

Posting Komentar