Usually we want to check all arrangements of n different elements to determine a best arrangement. For example, the arrangements of A, B, and C are: ABC, ACB, BAC, BCA, CAB, and CBA. N elements are arranged in N!
/ / Generate all arrangements VOID Perm (CHAR LIST [], INT K, INT M) {INT i; if (k == m) {for (i = 0; i <= m; i ) {Printf ("% C", list [i]); printf ("/ n");}}}} else {for (i = k; i <= m; i ) {swap (list k, list I); Perm (List, K 1, M); SWAP (List K, List I);}}}
Ref: << Data Structure, Algorithm & Applications >> P7 ~ P8