finish permute algorithm with merge sort