So, read the records from input, then sort them in RAM and then write them to file.dat. Why do you have to sort the records on the hard disk?