作业帮 > 综合 > 作业

排列组合算法如何实现 一维数组 中元素的排列组合,并将其排列组合的所有情况输出?如:一个字符串数组 ABC;排列后输出:

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/10 15:58:19
排列组合算法
如何实现 一维数组 中元素的排列组合,并将其排列组合的所有情况输出?
如:一个字符串数组 ABC;
排列后输出:ABC
ACB
BAC
BCA
CAB
CBA
我说的是用计算机代码表示的算法!不是怎么算!阶乘计算我会!
排列组合算法如何实现 一维数组 中元素的排列组合,并将其排列组合的所有情况输出?如:一个字符串数组 ABC;排列后输出:
可用递归算法 实现N重循环 来实现
详细请QQ :115499275
以下也许有助于你
以下为文件的内容:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 8115
ClientLeft = 60
ClientTop = 345
ClientWidth = 5760
LinkTopic = "Form1"
ScaleHeight = 8115
ScaleWidth = 5760
StartUpPosition = 3 '窗口缺省
Begin VB.ComboBox Combo1
Height = 300
Left = 4200
TabIndex = 2
Text = "Combo1"
Top = 960
Width = 1215
End
Begin VB.TextBox Text1
Height = 7455
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 1
Text = "Form1.frx":0000
Top = 120
Width = 3855
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 4200
TabIndex = 0
Top = 120
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Pwd As String
Function NFormM(ByVal iStart As Integer,iEnd As Integer,Num As Integer,Optional Str As String)
Dim i As Integer
If Num = 0 Then
With Text1
.Text = Text1.Text & Str & vbNewLine
.SelStart = Len(.Text)
End With
Else
For i = iStart To iEnd
DoEvents
NFormM i + 1,iEnd,Num - 1,Str & Mid(Pwd,i,1)
Next
End If
End Function
Private Sub Command1_Click()
Dim out(),i As Integer,s As String
Text1.Text = ""
NFormM 1,Len(Pwd),Val(Combo1.Text)
End Sub
Private Sub Form_Load()
Dim i As Integer
With Combo1
For i = 1 To 12
.AddItem i
Pwd = Pwd & Chr(64 + i)
Next
Print Pwd
End With
End Su