nauczyć się permutacji sieci string vb
Mam tablicę znaków i chcę utworzyć permutację ze specjalnym warunkiem
na przykład, jeśli i wejście 2, to wygeneruje permutację 2 znaków tablica char zawiera 6 takich elementówinChars = {c,f,a,b,m,p)
kiedy go uruchomię
Wejście 3 znakowe, generuje permutacjęf,a,b
4 znaki ->f,a,b,m
moje pierwsze pytanie dlatego zaczyna się od drugiego elementu tablicy (f) zamiast (c)
i moje drugie pytania jak stworzyć coś takiego: kiedy wprowadzę 3 znaki, wygeneruje on 2 i 3 podzbiór znaków char zamiast tylko 3 podzbiorów, będzie to jak
c,f
c-a
....
c,f,a
c,a,m
.....
oto zrzut ekranu
oto kod
Public Class permute
Dim ItemUsed() As Boolean
Dim pno As Long, pString As String
Dim inChars() As Char = {"c", "f", "a", "b", "m", "p"}
Private Sub permute_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Sub Permute(ByVal K As Long)
ReDim ItemUsed(K)
pno = 0
Permutate(K, 1)
tb.Text = K
End Sub
Private Sub Permutate(ByVal K As Long, ByVal pLevel As Long)
Dim i As Long, Perm As String
Perm = pString
For i = 1 To K
If Not ItemUsed(i) Then
If pLevel = 1 Then
pString = inChars(i)
Else
pString += inChars(i)
End If
If pLevel = K Then
pno = pno + 1
Results.Text += _
pno & " " & " = " & " " & pString & vbCrLf
Exit Sub
End If
ItemUsed(i) = True
Permutate(K, pLevel + 1)
ItemUsed(i) = False
pString = Perm
End If
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Permute(tb.Text)
End Sub
Private Sub tb_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb.TextChanged
If tb.Text = "" Then
Results.Text = ""
Else
Permute(tb.Text)
End If
End Sub
End Class