Lexicographic permutation list
You might not be able to generate lexicographic permutations for any sequence of arbitrary objects. In order to do so, you will need some way of comparing two objects and determining which one is smaller.

Assuming you have this, you could use the following algorithm to generate all permutations of a sequence of $n$ objects in lexicographic order.


Start by sorting the input sequence, $A$, of $n$ objects
Find the largest index $k$ such that $A[k] &lt; A[k+1]$.  If no such $k$ is found, terminate. The sequence $A$ contains the last lexicographic permutation.
Find the largest index $l$ such that $A[k] &lt; A[l]$
Swap $A[k]$ and $A[l]$
Reverse the sub-sequence starting from $A[k+1]$ to the final element, $A[n-1]$


Note that this algorithm generates the next lexicographic permutation of $A$ in-place. To generate all permutations, you can repeat this until no more permutations are found.