Consider using something like the merge for merge-sort.