Make sure that your binary tree's node struct has data members name and count as well as left and right pointers.
Define a bool comesBefore( node a, node b ) function that returns whether a.count > b.count. Use this in your comparison that determines left or right for both insertion and writing out.