如何在不使用递归的情况下找到字符串的所有排列?
本文介绍了如何在不使用递归的情况下找到字符串的所有排列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能帮我解决这个问题:这是一个查找任意长度字符串的所有排列的程序.需要相同的非递归形式.(首选C语言实现)
Can someone help me with this: This is a program to find all the permutations of a string of any length. Need a non-recursive form of the same. ( a C language implementation is preferred)
推荐答案
基于堆栈的非递归等效代码:
A stack based non-recursive equivalent of your code:
我试图让它像 C 一样,并避免使用 c++ STL 容器和成员函数(不过为了简单起见,使用了构造函数).
I've tried to make it C-like and avoided c++ STL containers and member functions (used a constructor for simplicity though).
请注意,排列是按与原始顺序相反的顺序生成的.
Note, the permutations are generated in reverse order to the original.
我应该补充一点,以这种方式使用堆栈只是模拟递归.
I should add that using a stack in this way is just simulating recursion.
这篇关于如何在不使用递归的情况下找到字符串的所有排列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!