That makes sense to me.
Printable View
That makes sense to me.
I made the changes and some errors occured so I changed the things in bold. It executes without errors but my output is still displaying only the first element as before with blank lines for the other elements.
I am going crazy with this program. Please help me, if you can. Thanks.
Code:void HybridList::Insert( /* in */ me item )
// Precondition:
// component members of list nodes are in ascending order
// && item is assigned
// Postcondition:
// New node containing item is in its proper place
// in linked list
// && component members of list nodes are in ascending order
{
mePtr currPtr; // Moving pointer
mePtr prevPtr; // Pointer to node before *currPtr
mePtr newMePtr; // Pointer to new node
// Set up node to be inserted
newMePtr = new me;
newMePtr->lName = item.lName;
// Find previous insertion point
prevPtr = NULL;
currPtr = head;
while (currPtr != NULL && item.lName > currPtr->lName) // Error with this line
{
prevPtr = currPtr;
currPtr = currPtr->link;
}
// Insert new node
newMePtr->link = currPtr;
if (prevPtr == NULL)
head = newMePtr;
else
prevPtr->link = newMePtr;
}
What I see
newMePtr->lName = item.lName;
you initialize only lName in your stored data
If you want to store all strings you should copy all strings...
maybe something like
*newMePtr = item;
will work
also - to avoid unnecesary copying, I think you should pass me as const reference
void HybridList::Insert( /* in */ const me& item )
It works vart. Thank you.
Last question, I am currently outputting the list to the screen but I need it to print to a file called 'contact.dat'. How can I go about that in the Hybrid class print function?
Thanks
Look at a tutorial on file I/O. It's not a difficult thing.
I figured it out. I was forgetting to use include <fstream>. Thanks for all of the help and I really appreciate the help.
Check out this link to know more.Code:#include <fstream>
fstream binary_file("'contact.dat'.",ios::binary|ios::out);
binary_file.write(reinterpret_cast<char *>(currPtr),sizeof(me));
binary_file.close();
EDIT: It seems like I didn't post it in time. :D Sorry can't help much.