Get_Next的VB程式碼

laocooon發表於2015-10-05

Private Sub Command1_Click()

Dim i, j As Integer

Dim Next1(9) As Integer

Dim S, T(9) As String

S = "ababaaaba"

For i = 1 To UBound(Next1)

T(i) = Mid(S, i, 1)

Next

For i = 1 To UBound(Next1)

Debug.Print T(i)

Next

Get_Next T, Next1

End Sub

Private Sub Get_Next(T() As String, Next1() As Integer)

Dim i, j As Integer

i = 1

j = 0

Next1(1) = 0

Do While (i < UBound(Next1))

If (j = 0 Or T(i) = T(j)) Then

i = i + 1

j = j + 1

If T(i) <> T(j) Then

Next1(i) = j

Else

Next1(i) = Next1(j)

End If

Else

j = Next1(j)

End If

Loop

For i = 1 To UBound(Next1)

Debug.Print Next1(i)

Next

End Sub

相關文章