c04p201.txt

来自「Data Abstraction & Problem Solving with 」· 文本 代码 · 共 32 行

TXT
32
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?