Recursive To non-Recursive Procedure
Can anybody convert this recursive procedure to a non-recursive one?
========================================
Sub Permutation(Str1 As String, _
Optional Str2 As String = vbNullString, _
Optional ByRef Xrow As Long = 1)
Dim i As Integer, xLen As Integer, a As String, b As String
xLen = Len(Str1)
If xLen < 2 Then
Range("A" & Xrow) = Str2 & Str1
Xrow = Xrow + 1
Else
For i = 1 To xLen
a = Left(Str1, i - 1) & Right(Str1, xLen - i)
b = Str2 & Mid(Str1, i, 1)
Call Permutation(a, b, Xrow)
Next
End If
End Sub
========================================
The procedure is called, in the simplest way, with:
Call Permutation("string-to-permute").
Bruno
|