We present a new algorithm for iterating over all permutations of a sequence. The algorithm leverages elementary $O(1)$ operations on recursive lists. As a result, no new nodes are allocated during the computation. Instead, all elements are rearranged within the original nodes of the singly linked list throughout the process. While permutations are generated in an unusual order, the transitions between consecutive permutations remain smooth. A proof of concept written in the Lisp programming language is proposed and discussed.
翻译:本文提出了一种遍历序列所有排列的新算法。该算法利用递归链表的基本$O(1)$操作。因此,在计算过程中无需分配新节点。相反,所有元素在整个过程中都在单向链表的原始节点内重新排列。虽然排列的生成顺序较为特殊,但连续排列之间的转换依然保持平滑。文中提出并讨论了一个用Lisp编程语言编写的概念验证实现。