abcd 的全排列代码
时间: 2023-10-25 11:10:15 浏览: 86
全排列源代码
以下是使用递归方式实现的abcd的全排列代码:
```python
def permute(data, i, length):
if i == length:
print(''.join(data))
else:
for j in range(i, length):
# swap
data[i], data[j] = data[j], data[i]
# recursive call
permute(data, i+1, length)
# swap back
data[i], data[j] = data[j], data[i]
# test the function
data = list('abcd')
permute(data, 0, len(data))
```
输出结果为:
```
abcd
abdc
acbd
acdb
adcb
adbc
bacd
badc
bcad
bcda
bdca
bdac
cbad
cbda
cabd
cadb
cdab
cdba
dbca
dbac
dcba
dcab
dacb
dabc
```
阅读全文