CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    78

    Linked list input question

    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;
    }
    }

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Linked list input question

    Quote Originally Posted by XodoX View Post
    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.
    Please post compilable code that is properly indented.
    Also, what is your actual question?
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured