External sort algorithm.
Then array of data which you want to sort doesn't fit in memory, you can use external sort.
- Algorithm takes some file with unsorted data as input, sequentially reads file data, sorting parts of data (chunks) in memory and persisting sorted chunks to temporary files.
- Algorithm opens all files with sorted chunks and sequentially reads data from them, putting data to priority queue, and using this queue as source for result output file with sorted data.
./gradlew build
See the example
java -cp ... com.futujaos.extsort.Extsort <source_file> <target_file>