Character: full array

Full array

Dian a recursive algorithm

Here Insert Picture Description
Every time that a fixed, full array behind looking recursive

How to solve the problem of repeat

We use only the last recurring, check back every time there have been no figures again, there will continue, no operation can be performed recursively, comparing here is O (n) a. If you need faster we can directly use the space flag is visited, which is O (1), but this algorithm to finally factorial level.

Dian two non-recursive algorithm

Generating a sequence of small to large, for example

123 ,132 ,213, 231,312,321

The key issue is to find the next one next to the arrangement, as follows
Here Insert Picture Description

C ++ STL has been integrated in Algorithm in
next_permutation

If equal, then next slide

Published 124 original articles · won praise 92 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_42146775/article/details/103753266