Build a minheap using the frequency of each letter as the key. The other value with the key is a tree with a single node which contains the letter.
While there is more than one element in the heap, remove two items from the heap. Build a new item with the key being the sum of the two keys and a tree which has left and right children from the two removed items. Place this new item in the heap.
Now the single item in the heap has the Huffman tree in it. Remove that item and traverse the tree, outputting the Huffman code.