漠然としているように見えるかもしれませんが、本当に申し訳ありません。私はファイルに書き込み、この単一リンクリスト内のソートされたノードをコンソールに出力しています。残念ながら、ソートリストでは、先頭に余分な0を出力して書き込み、最後に値を切り取ります。コードは次のとおりです。
void SLLIntStorage::Read(istream& r)
{
char c[13];
r >> c;
r >> numberOfInts;
head = new Node;
head->next = NULL;
tail = head;
r >> head->data;
for (int i = 0; i < numberOfInts; i++)
{
Node* newNode = new Node;
r >> newNode->data;
if(_sortRead)
{
if(newNode->data > tail->data)
{
tail->next = newNode;
tail = newNode;
}
else if(head->data > newNode->data)
{
newNode->next = head;
head = newNode;
}
else
{
current = head;
while(current->next != NULL)
{
if(current->next->data > newNode->data)
{
newNode->next = current->next;
current->next = newNode;
break;
}
else
{
current = current->next;
}
}
}
}
else
{
tail->next = newNode;
tail = newNode;
}
}
print();
}
void SLLIntStorage::Write(ostream& w)
{
current = head;
for(int i = 0; i < numberOfInts; i++)
{
w << current->data << endl;
if (current->next != NULL)
current = current->next;
}
}
void SLLIntStorage::print()
{
current = head;
for(int i = 0; i < numberOfInts; i++)
{
cout << current->data << endl;
//system("pause");
if(current->next != NULL)
{
current = current->next;
}
}
}
ファイルサンプル: 0 0 1 2 2 3 ........ 9995 9996 99969998 //ここでは別の9998と想定