working merge sort in both directions