Question: In c++ how would you copy records from a text file into a doubly linked list. I believe my function to load them to a
In c++ how would you copy records from a text file into a doubly linked list. I believe my function to load them to a doubly linked list works but Im not sure how to set up my main function. load function is as followed:
list::list() { first = NULL; } void list::load() { item *current; item *prev; ifstream fin; fin.open("List.txt"); prev = NULL; while(!fin.eof()) { current=new item; if (first == NULL) // we set first the first time first = current; fin>>current->name; current->previous=prev; current->next = NULL; if (prev != NULL) prev->next=current; prev = current; // we store the current as the prev for next iteration } fin.close(); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
