Setting up a linked list?

Discussion in 'C++' started by deker9, Oct 14, 2011.

  1. deker9

    deker9 New Member

    Joined:
    Oct 14, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I'm reading a text file into the program with the following format:
    Code:
    Becker John P
    Ury Ismael C
    Joker Samuel P
    Sampson Kelly C
    My code is below:
    Code:
    struct Roster {
        string LName;
        string FName;
        char Cheesecake;
        Roster *next, *prev;
    };
    
    inFile.open(file_name);
    
        Roster * head;
    
        for (int record = 0;record < numRecords;record++)
            {
                static Roster * thisRoster = new struct Roster;
                inFile >> thisRoster->LName;
                inFile >> thisRoster->FName;
                inFile >> thisRoster->Cheesecake;
                cout << (*thisRoster).LName << " " << (*thisRoster).FName << " " << (*thisRoster).Cheesecake << endl;
                
    
            }
    My issue is that I'm not sure how to "link" these together. I'm then supposed to be able to sort by last name etc. Can someone maybe give me pointers or help me modify this code to suit those purposes?
     
  2. neerjasoftwares

    neerjasoftwares New Member

    Joined:
    Oct 17, 2011
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Drupal Developer
    Location:
    Jaipur, Rajasthan, India
    Home Page:
    http://www.neerjasoftwares.com
    hello dear.....................
    Neerja Softwares.com launched a quick series on pointers giving the explanation of each and every topic that we face daily.
     

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