题目:输入一个字符串,打印出该字符串中字符的所有排列。

53.字符串的排列。
题目:输入一个字符串,打印出该字符串中字符的所有排列。
例如输入字符串abc,则输出由字符a、b、c所能排列出来的所有字符串abc、acb、bac、bca、cab和cba。

分析:这是一道很好的考查对递归理解的编程题,
因此在过去一年中频繁出现在各大公司的面试、笔试题中。

VB.NET codes :

Module MyModule

Sub Main()

Print("FXF")

Console.ReadKey()

End Sub

Public Sub Print(ByVal str As String, Optional ByVal partStr As String = Nothing)

If str = Nothing Or str.Length = 0 Then

If Not partStr Is Nothing Then

Console.WriteLine(partStr)

End If

Return

End If

For i = 0 To str.Length - 1

Dim newPartStr = partStr + str(i)

Dim newStr = str.Remove(i, 1)

Print(newStr, newPartStr)

Next

End Sub

End Module

你可能感兴趣的:(字符串)