I'm not sure if this is correct. The input is stored in a variable and I used that variable for the linked list.
I jsut need the input in the list and then I go from there. So no deleting needed. Just the adding, I suppose.
Code:string Input; string filepath("filename.txt"); ifstream fin; fin.open(filepath); if(fin.is_open()) { getline(fin,Input,'\x1A'); fin.close(); } else { cout << "Error: Could not open file.\n"; } // linked list void List::appendNode (string Input) { ListNode *newNode; // point to new node ListNode +nodePtr; // to move through the list //Allocate a new node and store input there newNode = new ListNode; newNode->value = string; newNode->next = NULL; // if no nodes in list make newNode first node if (!head) head = newNode; else { //initialize nodePtr to head of list nodePtr = head; //find last node in List while (nodePtr->next) nodePtr = nodePtr->next; //Insert new node in the last node nodePtr-> next = newNode; } }


Reply With Quote


Bookmarks