Implement stable merge sort for testing.