vendredi 28 mai 2010

Given a set of characters, print out all possible permutations.

take out one element of the list at a time
generate a new list with that element and the permutations of the list except that element (recursive), return the new list



perm(l)
if len(l) = 0:
return []
elif len(l) == 1:
return [l]
else
P = []
for e in l:
v = l\e
P.add ( [e] + perm(v) )
return P

Aucun commentaire:

Enregistrer un commentaire