Enumeration of set partitions
An algorithm for generating all partitions of $n$ elements into $k$ sets is given in Volume 4A of Knuth's The Art of Computer Programming (which was apparently finally published last year; I didn't know that). The subsection is available on his website as fascicle 3b; the algorithm is on page $27$.