merge sort using stack and high-level functions