我知道External merge sort以及它是如何工作的。 但目前我卡住实施它。我写的代码进行排序和合并的阵列,但我现在面临的问题,同时读取和/数据写入到文件,我想实现在C++以下方法:实现外部合并排序
1. int * read(int s, int e) : This method should read from file all the number
starting from 's' till 'e' and return the array
2. write(int a[], int s, int e) : This method should write to file the input
array by replacing the numbers from s to e.
对于如。
Given file has the following numbers:
1
2
3
4
5
6
read(0, 2) should return [1,2,3]
write([4,5,6], 0, 2) should update the file to :
4
5
6
4
5
6
我该如何实现这两种方法?
正如Yakk所说,通过使用istream :: seekg和istream :: tellg函数,可以跳转到文本文件中的一行。但是,我不确定这些功能的时间复杂性和效率。 请参阅以下链接中的示例:http://www.cplusplus.com/reference/istream/istream/seekg/ – 2016-04-21 21:47:11