Replace bubble sort with heap sort.

Probably faster, and it saves a couple temporary arrays, but at least the
name is no longer false.