123456789101112131415161718192021222324252627282930313233343536373839
oid List::load( string fileName ) throw( ListException ) { ifstream inFile( fileName.c_str() ); ListItemType nextItem; ListNode *tail; while (!isEmpty()) { remove( 1 ); } size = 0; if (inFile >>nextItem) { try { head = new ListNode; //Add the first char to the list head->item = nextItem; head->next = NULL; tail = head; size = size+1; //Add remaining integers to linked list while( inFile >>nextItem) { tail->next = new ListNode; tail = tail->next; tail->item = nextItem; tail->next = NULL; size = size+1; } } catch(...) { throw ListException("ListException: restore cannot allocate memory."); }//end try }//end if inFile.close(); }