|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
用递归算法列出7个字母的组合与每个组合的全排列,不用递归能实现吗?
原代码如下:
Dim Zeile
Sub hh()
Dim ar(1 To 7) As String
Dim x As Integer
ar(1) = "a"
ar(2) = "b"
ar(3) = "c"
ar(4) = "d"
ar(5) = "e"
ar(6) = "f"
ar(7) = "g"
p = 1
Zeile = 1
Call ff("", p, ar())
End Sub
Sub ff(x As String, z, a() As String)
For i = z To UBound(a())
If i > UBound(a()) Then
Exit Sub
Else
'Debug.Print x & a(i)
'Zeile = Me.Rows.Row
Call Textdreher("", x & a(i))
End If
Call ff(x & a(i), i + 1, a())
'Zeile = Zeile + 1
Next
End Sub
Sub Textdreher(x As String, y As String)
Dim i As Integer, j As Integer
j = Len(y)
If j < 2 Then
Cells(Zeile, 1) = x & y
Zeile = Zeile + 1
'Debug.Print x & y
Else
For i = 1 To j
Call Textdreher(x + Mid(y, i, 1), Left(y, i - 1) + Right(y, j - i))
Next
End If
End Sub |
|