在此处输入图像描述 我有 3 个包含字符串的文本文件。我希望它们使用带有 c++ 的堆存储在优先级队列中。
我只能从文件部分进行 reding 并存储到数组中。我想使用堆将文本文件中的字符串存储到优先级队列中。但我不知道怎么做。
enter code here
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include<chrono>
using namespace std;
class PriorityQueue{
};
int main () {
int choice, choice2;
//priority_Queue prio;
string item;
string *datasetA = new string[100];
string *datasetB = new string[1000000];
string *datasetC = new string[5000000];
short loop=0;
string line;
while(1){
cout << "1.Insert SetA" << endl;
cout << "2.Insert setB" << endl;
cout << "3.Insert setC" << endl;
cout << "4.Exit" << endl;
cout << "Enter your Choice: ";
cin >> choice;
switch(choice){
case 1:{
ifstream myfile ("setA.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
datasetA[loop] = line;
cout << datasetA[loop] << endl;
loop++;
}
myfile.close();}
else cout << "can't open the file";
system("PAUSE");
}
break;
case 2:{
ifstream myfile ("setB.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
datasetB[loop] = line;
cout << datasetB[loop] << endl;
loop++;
}
myfile.close();}
else cout << "can't open the file";
system("PAUSE");
}break;
case 3:{
ifstream myfile ("setC.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
datasetC[loop] = line;
cout << datasetC[loop] << endl;
loop++;
}
myfile.close();}
else cout << "can't open the file";
system("PAUSE");
return 0;
}
case 4:{
cout<< line<<endl;
}
case 5:{
exit(1);
}break;
default:
cout << "Wrong Choice" << endl;
}
}return 0;}