Stuck in an endless loop in method for a linked list class

Discussion in 'C++' started by wittykitty, Sep 9, 2010.

  1. wittykitty

    wittykitty New Member

    Joined:
    Sep 9, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I seem to be stuck in an endless loop here and was wondering if someone could help? I am writing this method to a linked list class. There are strings of words in a file that is read into the linked list. It needs to read the last string in the file (eg: happy) then run back through the linked list, and anything less than happy (any word starting with a-g) it will delete from the list and create a new list with the deleted nodes. I have a deleteNode method written also. Any help is appreciated!

    Code:
    void list::outputResult(ostream& outstream)
    {
    
      node *nodeptr;
      string data;
      
      nodeptr = head;
      while(nodeptr->link != NULL)
      {
      nodeptr = nodeptr->link;
      }
      
      nodeptr->data;
      string temps = nodeptr->data;
    
      nodeptr = head;
      while(nodeptr->link != NULL)
      {
      
      if(nodeptr->data < temps)
      {
      deleteNode(data);
      nodeptr = head;
      }
      else
      nodeptr = nodeptr->link;
      }
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice