sorting - 将随机数生成到打印到 Txt 文件的数组中。在点击文本文件之前,需要对数字进行排序
问题描述
所以我的目标是基本上将 40,000 到 1,000,000 的随机数打印到 txt 文件中,并使用堆方法进行排序。我可以用随机数很好地打印到文本文件,但我有点坚持使用堆方法对它们进行排序。在看了一些教程后,我开始了一个方法,并在中途迷失了方向。有什么想法/有用的评论吗?我从字面上看是堆栈溢出的新手(明智地发布),所以如果我没有正确地将它放在这里,请原谅我。谢谢!
//Heapsort algorithm
#include <iostream>
#include <string>
#include <fstream>
#include <ctime>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
/*class generateDataSet {
public: static const int MAX_VALUE = 1000000;
public: static const bool SORTED = false;
public: static const bool REVERSE_SORTED = false;
};
*/
int main()
{
const int array= 16;
int arrayNum[array];
srand(time(NULL));
int upB = 1000000;
int loB = 40000;
int temp;
ofstream inputFile;
inputFile.open("randomData.txt");
if (inputFile.is_open())
{
for (int i = 0; i < array; i++)
{
arrayNum[i] = (rand()% (upB - loB + 1)) + loB;
inputFile << arrayNum[i] << "\n";
}
}
return 0;
}
void MaxHeapify(int d[], int i, int n)
{
int j;
int temp;
temp = d[i];
j = 2 * 1;
while (j <= n)
{
if (j < n && d[j + 1] > d[j])
j = j + 1;
if (temp > d[j])
break;
else if (temp <= d[j])
{
d[j / 2] = d[j];
j = 2 * j;
}
}
}
void heapSort(int d[], int n)
{
int i;
int temp;
for (i = n; i >= 2; i);
}
解决方案
推荐阅读
- c++ - 错误:必须使用“类”标签来引用此范围内的“变量”类型
- pytorch - pytorch 的 grid_sample 返回不正确的值
- cassandra-3.0 - cassandra中的节点工具修复后的反压缩阶段
- mysql - 在批处理文件中提供 MySQL 密码的安全方法
- java - Android Picasso 导致 W/System: A resource failed to call close
- java - 如何为tomcat拆分catalina.out?
- c# - ORM - 在静态上下文中获取基类的类型?
- amazon-web-services - 无法在 aws http api 上发布数据?
- python - 如何在python中加入像拼图这样的矩阵
- android - 如何强制 Android 11 上的 OkHttp 使用 TLS 1.3 发送 ssl 客户端证书身份验证