I have difficulty resolving one sort of simple task. The goal of the task is to combine two binary files into a third, and after the third file, sort in descending order. The resulting file will look something like this:
52,sdads
34,dsad
98,dasd
22,asdas
And I have to sort all these lines in descending order by the numbers. Please at least someone can tell how this can be implemented. What algorithm do I need to solve the problem, or help with what I need to start. I will be very grateful!
int main(){
ofstream ofs("f3", ofstream::binary);
ifstream ifs;
ifs.open("f1", ifstream::binary);
ifs.seekg (0, ifs.end);
int len = ifs.tellg();
ifs.seekg (0, ifs.beg);
char * buffer = new char [len];
ifs.read(buffer, len);
ofs.write(buffer, len);
ifs.close();
delete[] buffer;
ifs.open("f2", ifstream::binary);
ifs.seekg (0, ifs.end);
len = ifs.tellg();
ifs.seekg (0, ifs.beg);
buffer = new char [len];
ifs.read(buffer, len);
ofs.write(buffer, len);
ifs.close();
delete[] buffer;
}