16,554
社区成员
发帖
与我相关
我的任务
分享
Public Sub Permutation(pre As List(Of Int16), Slist As List(Of Int16), outlist As List(Of List(Of Int16)))
If Slist.Count = 1 Then
Dim Mrang As New List(Of Int16)
Mrang.AddRange(pre)
Mrang.AddRange(Slist)
outlist.Add(Mrang)
Return
End If
For i As Int16 = 0 To Slist.Count - 1
Dim Mint16 As Int16 = Slist(i)
Dim Mprelist As New List(Of Int16)
Mprelist.AddRange(pre)
Mprelist.Add(Mint16)
Dim MSlist As New List(Of Int16)
MSlist.AddRange(Slist)
MSlist.RemoveAt(i)
Permutation(Mprelist, MSlist, outlist)
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Slist As New List(Of Int16)
For i As Int16 = 1 To 4
Slist.Add(i)
Next
Dim Mpre As New List(Of Int16)
Dim Moutlist As New List(Of List(Of Int16))
Permutation(Mpre, Slist, Moutlist)
Dim sb As New System.Text.StringBuilder
For Each li As List(Of Int16) In Moutlist
For Each mint As Int16 In li
sb.Append(mint)
Next
sb.Append(vbCr)
Next
Debug.Print(sb.ToString)
End Sub