相关疑难解决方法(0)

随机数外部排序

我需要编写一个程序来生成 N 个随机数并按降序将它们写入二进制文件。它应该在不使用任何使用主内存的排序算法的情况下完成。这是我到目前为止所做的:

#include <iostream>
#include <fstream> 
#include <ctime>
#include <cstdlib>

using namespace std;
int main () {
  srand(time(0));
  rand();
  int N;
  do{
    cout << "Unesite N: ";
    cin >> N;
    } while(N<=0);

  ofstream br("broj.dat", ios::binary | ios::trunc);

  for(int i = 0; i<N; i++){
    int a = rand();
    br.write((char *)&a, sizeof(a));
  }
  br.close();

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

所以,我生成了随机数并将它们写入二进制文件,但我不知道如何对其进行排序。

c++ sorting random algorithm binaryfiles

1
推荐指数
1
解决办法
223
查看次数

标签 统计

algorithm ×1

binaryfiles ×1

c++ ×1

random ×1

sorting ×1