Struct BinaryData {double Data; BinaryData * Next; };
//input binary data
Int InputBinaryData (BinaryData * & amp;);
//exchange element
Void Swap (double& , double&);
//prioritize
list since the childhoodVoid ListSortUp (BinaryData * & amp;);
//create a binary file
Void CreateAscendingOrderBinaryFile (char *);
//implementation. CPP
# include & lt; Iostream>
# include & lt; Fstream>
# include "header. H
"using namespace std;
//input binary data and return a list of chain length
Int InputBinaryData (BinaryData * & amp; HeadOfList)
{
Int ListLength=0;
LinkPoint BinaryData * NewPoint=NULL, *=NULL;
Cout & lt; <"Please input data, end please click " Ctrl + Z \ "key combination:";
NewPoint=new BinaryData;
While (cin & gt;> NewPoint - & gt; Data)
{
If (HeadOfList==NULL) {HeadOfList=NewPoint; }
The else
{
If (LinkPoint!=NULL) {LinkPoint - & gt; Next=NewPoint; }
The else {cout & lt; <"Pointer error... \n"; Abort (); }
}
LinkPoint=NewPoint;
ListLength=ListLength + 1;
NewPoint=new BinaryData;
}
If (LinkPoint!=NULL) {LinkPoint - & gt; Next=NULL; }
The delete NewPoint;
NewPoint=NULL;
Return ListLength;
}
//exchange element
Void Swap (double& Data1, double& Data2)
{
Double ExchangeData=https://bbs.csdn.net/topics/0.0;
ExchangeData=https://bbs.csdn.net/topics/Data1;
Data1 Data2=;
Data2=ExchangeData;
}
//to smallest to list
Void ListSortUp (BinaryData * & amp; HeadOfList)
{
BinaryData * FormerPoint=NULL, * LatterPoint=NULL;
For (FormerPoint=HeadOfList; FormerPoint!=NULL & amp; & FormerPoint - & gt; Next!=NULL; FormerPoint=FormerPoint - & gt; Next)
{
For (LatterPoint=FormerPoint - & gt; Next; LatterPoint!=NULL; LatterPoint=LatterPoint - & gt; Next)
{
If (FormerPoint - & gt; The Data & gt; LatterPoint - & gt; Data) {Swap (FormerPoint - & gt; The Data, LatterPoint - & gt; The Data); }
}
}
}
//create a binary file
Void CreateAscendingOrderBinaryFile (char * FileName)
{
Int ListLength=0, Subscript=0;
BinaryData * HeadOfList=NULL;
Fstream BinaryFile;
//input file name
Cout & lt; <"Please input file:";
FileName=new char [100].
Cin. Getline (FileName, 100);
//open the file
BinaryFile. Open (FileName, the ios: : out | ios: : binary);
if (! BinaryFile) {cerr & lt; <"File cannot be created or opened... \n"; Abort (); }
//input data
ListLength=InputBinaryData (HeadOfList);
//used to sort the data
ListSortUp (HeadOfList);
//to write data into the binary file
For (; Subscript & lt; ListLength; Subscript Subscript +=1)
{
BinaryFile. Write ((char *) & amp; HeadOfList - & gt; The Data, sizeof (double));
Cout & lt;
}
//close the file
BinaryFile. Close ();
}
//the main function. The CPP
# include & lt; Iostream>
# include
# include "header. H
"using namespace std;
Int main ()
{
Char * File1=NULL, * File2=NULL;
CreateAscendingOrderBinaryFile (File1);
CreateAscendingOrderBinaryFile (File2);
The delete [] File1;
The delete [] File2;
}
[question] : input the first file name and the data is no problem, but the time to open the second file open failed, I look at the baidu said need "BinaryFile. The clear ()" this function will flow state, but I'm not add to (the) is not above, I am not familiar with respect to the operation this, find out problems, request, some directions, thank you!!!!!
[error screenshot] :