本文整理汇总了C++中LinkedList::AppendNode方法的典型用法代码示例。如果您正苦于以下问题:C++ LinkedList::AppendNode方法的具体用法?C++ LinkedList::AppendNode怎么用?C++ LinkedList::AppendNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedList
的用法示例。
在下文中一共展示了LinkedList::AppendNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadDataFile
void ReadDataFile(){
cout << "Opening data file 'data_" << FileNumber << ".txt'..." << endl;
string file = "data_" + FileNumber + ".txt";
DataFile.open(file.c_str());
if (!DataFile){
TerminateError("Unable to open data file.");
}
ListNode<ListNodeData> *node = NULL;
//Find the last node to append the list, if the list is already with items.
TheList.Rewind();
while (TheList.Current() != NULL){
node = TheList.Current();
TheList.Next();
}
string text, dummy;
int number;
//Read data file into list
while (!DataFile.eof()){
GetLine(DataFile, text); //GetLine gets rid of newline character.
if (DataFile.eof()){ //EOF was reached before a number is read!? Means file is malformed. Ignoring final node.
cout << "Unexpected end of file for data file. Finishing read." << endl;
break;
}
DataFile >> number;
getline(DataFile, dummy); //Use GetLine to clear the newline character.
//The default behaviour of inserting new nodes to the list is by inserting it at the first node.
//So we need a "workaround" to build the list as it was defined in the data file.
cout << "Appending Node " << text << " " << number << endl;
if (node == NULL){
node = TheList.InsertNewNode(ListNodeData(number, text)); //This is the first node.
}
else{
node = TheList.AppendNode(node, ListNodeData(number, text)); //Append additional node behind the first node
}
}
DataFile.close();
}