I'd hate to just give the answer away, but Google is your friend. Wikipedia: Generate Permutations in Lexicographic Order (the page also has other possible ways to generate permutations). Feel free...