Hello all, I'm having a bit of trouble logically figuring out what to do in this case for my cs150 class. I have to create a linked list from a while loop, but I can't figure out how to link the list successively at the end of each line so that it creates a nice chain.
My original thought was to create a node outside the loop, read the first line, then start the loop at line 2 and after each struct is filled, link the first to that one, create a second temp node to link to the first, then after the next line, link the first to the last/most current, the temp to the previous, and the most current back to the first. (I think)
After that, I need to sort the names in order by ID, but I'm unsure how to do this since I believe my linked list will only follow it's chain as it was created, and I would have to set up some sort of condition that creates links based on some sort of lowest -> highest struct selection sort (for info.id).
Any guidance is greatly appreciated; I'm still trying to think this one through and running into some trouble.
Thanks for any help!
inFile.open("peeps.txt");
if(!inFile)
{
cout << "Too bad. No File.";
}
nodeType *first, *next;
first = new nodeType; //00x
inFile >> first->info.firstname;
inFile >> first->info.id;
inFile >> first->info.height;
inFile >> first->info.weight;
first->link = NULL;
while (inFile)
{
next = new nodeType; //01x
inFile >> next->info.firstname;
//trouble ahead trouble ahead
first->link = next; //meh
}