






















A permutation can be obtained by selecting an element in the given set and recursively permuting the remaining elements.


At each stage of the permutation process, the given set of elements consists of two parts: a subset of values that already have been processed, and a subset that still needs to be processed. This logical seperation can be physically realized by exchanging, in the i’th step, the i’th value with the value being chosen at that stage. That approaches leaves the first subset in the first i locations of the outcome.

1 permute(i) 2 if i == N output A[N] 3 else 4 for j = i to N do 5 swap(A[i], A[j]) 6 permute(i+1) 7 swap(A[i], A[j])
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。