阐述了磁盘文件排序,一步步问题陈述,将最后问题归纳如下:
给出如下最简单的解法:
代码缩小了问题的规格实现如下:
#include<fstream>
#include<assert.h>
using namespace std;
const int NUB = 1000000;
typedef unsigned int U32;
inline void SetBitArray(U32* arr, U32 len, U32 n)
{
assert(n < (len << 5));
arr[n >> 5] |= (0x1UL << (n & 0x1f));
}
bool BitValArray(U32* arr, U32 len, U32 n)
{
assert(n < (len << 5));
return (arr[n >> 5] >> (n & 0x1f)) & 0x1;
}
int main()
{
fstream input("input.txt");
ofstream output("output.txt");
U32 nub = 0;
U32 bitVal[NUB / 32 + 1] = { 0 };
U32 len = NUB / 32 + 1;
while (input >> nub)
{
SetBitArray(bitVal, len, nub);
}
for (U32 i = 0; i < NUB; i++)
{
if (BitValArray(bitVal, len, i))
output << i<<endl;
}
return 0;
}
![](https://i-blog.csdnimg.cn/blog_migrate/655520074ba4d5d701ef6076aea2a370.png)