Thread: Need help with HybridList class errors......

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    That makes sense to me.

  2. #17
    Registered User
    Join Date
    Dec 2006
    Posts
    22
    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;
    }

  3. #18
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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 )
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #19
    Registered User
    Join Date
    Dec 2006
    Posts
    22
    It works vart. Thank you.

  5. #20
    Registered User
    Join Date
    Dec 2006
    Posts
    22
    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

  6. #21
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Look at a tutorial on file I/O. It's not a difficult thing.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  7. #22
    Registered User
    Join Date
    Dec 2006
    Posts
    22
    I figured it out. I was forgetting to use include <fstream>. Thanks for all of the help and I really appreciate the help.

  8. #23
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    Code:
                 #include <fstream>
                 fstream binary_file("'contact.dat'.",ios::binary|ios::out);
                 binary_file.write(reinterpret_cast<char *>(currPtr),sizeof(me));
                 binary_file.close();
    Check out this link to know more.

    EDIT: It seems like I didn't post it in time. Sorry can't help much.
    Last edited by g4j31a5; 12-15-2006 at 07:01 AM.
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  2. Class Errors (LNK2005)
    By NMZ in forum C++ Programming
    Replies: 4
    Last Post: 02-28-2005, 03:52 PM
  3. errors in my class....
    By o0obruceleeo0o in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2003, 03:22 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. class member access denied
    By chiqui in forum C++ Programming
    Replies: 2
    Last Post: 05-27-2002, 02:02 PM