No, that's the first step, which allows you to save some time.
Instead of starting the merge sort algorithm with blockSize = 1, you can start it with blockSize = 256000, but you'll need a file that contains sorted blocks of 256000 lines. That's where you are going to use the vector and sort().
- f := [A, B].
- fileId := 0.
- while not end of file X:
- vector := read 256000 lines from file X,
- sort vector,
- write vector to file f[fileId],
- fileId := 1 - fileId.
- blockSize := 256000.
- go to 3 from post #23.
Merge sort is one of the basic algorithms that every programmer should know. If you need more explanations, see Algorithms + Data Structures = Programs by Niklaus Wirth.
Bookmarks