📄 c04p201.txt
字号:
// Creates a linked list from the data in a text // file. The pointer variables head and tail are// initially NULL. fileName is a string that names// an existing external text file.ifstream inFile(fileName);int nextItem;if (inFile >> nextItem) // is file empty?{ // file not empty: head = new Node; // add the first integer to the list head->item = nextItem; head->next = NULL; tail = head; // add remaining integers to linked list while (inFile >> nextItem) { tail->next = new Node; tail = tail->next; tail->item = nextItem; tail->next = NULL; } // end while} w// end ifinFile.close();// Assertion: head points to the first node of the// created linked list; tail points to the last// node. If the file is empty, head and tail are// NULL (list is empty).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -