SOURCE FILE: createList.cpp


// 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 F(FileName);
int      NextItem;

if (F >> 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 (F >> NextItem)
   {  Tail->Next = new node;
      Tail = Tail->Next;
      Tail->Item = NextItem;
      Tail->Next = NULL;
   }  // end while
}  // end if

F.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).