Module 9 · Backtracking · Backtracking: Inclusion–Exclusion

Permutations

Keep an AvailableBox that gives you an item and takes it back — that is the whole template. A call buildPermutations fills the next place of currList: for every value still in the box it polls one (pollElement), goes deeper, then removes it (pollLast) and puts it back (putElement) so the next branch can use it. In the box, the place a number left stays dashed until it comes back. In the tree a box shows the list a call starts from, a branch shows the number polled, and every leaf adds one permutation.