You might also want to consider looking at std::stable_sort() and list::sort().