Regeneration and arrangement

zhaozj2021-02-16  54

The author has written a recursive and combination algorithm (http://www.9cbs.net/develop/read_article.asp?id=23809), which gives one altered recursive algorithm, please advise.

PRIVATE SUB Command1_Click () list lists the full-ranking DIM A (8) AS String, Temp as Stringfor I = 0 to 8A (i) = inexttemp = permutation (a)) debug.print tempdebug.print "Again" & Ubound (Split (Temp, VBCRLF)) 1 & "Sounds!" End Subfunction AddXTOStr (Byval X0 As String) AS String 'EG: X0: "1, 2, 3, 4 ", WE WILL ADD 5 To X0Dim Temp, Temp2, All () AS String, I as longtemp = split (x0,", ") Redim all (uBound 1) all (0) = xadd &", "& x0 'return" 5, 1, 2, 3, 4 "for i = 1 to Ubound (all) TEMP2 = TempTemp2 (i - 1) = Temp2 (i - 1) &", "& xadd' add 5 betWeen every two contunious numberall (i) = Join (temp2, ",") Nextaddxtostr = Join (all, vbCrLf) Set temp = NothingSet temp2 = NothingErase allEnd FunctionFunction permutation (ByRef a () As String, ByVal n As Long) As String ' List array A former N-1 Elements of All Arrange DIM I as Stringif N = 0 Then Permutation = a (0) IF n = 1 Then Permutation = a (0) & ", "& a (1) & VBCRLF & A (1) &", "& A (0) IF n> 1 THENTEMP = Split (Permutation (A, N), VBCRLF) 'Recursive Redim All (U Bound (Temp)) for i = 0 to Ubound (Temp) All (i) = addXTOSTR (Temp (i), A (N)) NextPermutation = Join (all, vbcrlf) end ifrase Allend Function

转载请注明原文地址:https://www.9cbs.com/read-23733.html

New Post(0)