External sorting algorithm