title: Converting an array implementation into a linked list ADT
body: <p>What do I need to do to the following code to make it a linked list implementation instead of an array implementation?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;iomanip&gt;
  //#include "Player.h"
  
  using namespace std;
  
  class Player 
  {
      private:
          string first;  // player's first name
          string last;   // player's last name
          string pos;   // player's primary position
          double batave;  // batting average
  
  
      public:
          Player(); // Default Constructor
  
          void Initialize(string, string, string, double); // copies data into the object with some simple formatting and data checking
  
          void Read(istream&amp;); // define methods to read and write simple versions of player data to/from 
  
          void Write(ostream&amp;);
  
          double getBattingAverage(); // define get/sets as needed
  
          string getFirstName();
          string getLastName();
          string getFullName();
          string getPosition();
  };
  
  
  Player::Player() // Default constructor - set player to predefined values
  {
      // use the Initialize method since we have one
      Initialize("unknown", "unknown", "tbd", 0.0);
  }
  
  
  void Player::Initialize(string first, string last, string pos, double avg) // copies data into the object with some simple formatting and data checking
  {
      first = first;
      last = last;
      pos = pos;
      if (avg &lt; 0) avg = -avg;  // at least try to correct
      batave = avg;
  }
  
  // define methods to read and write simple versions of player data
  // to/from streams
  
  // Read assumes the player's data is in the input stream in the format:
  // firstname lastname position average with only spaces between the data
  // no other separator characters are used.  This will not work if a player's 
  // name has embedded spaces!
  void Player::Read(istream &amp;input) 
  {
      char temp[100];  // using a temporary buffer to read input from stream
      input &gt;&gt; temp;
      first = temp;
      input &gt;&gt; temp;
      last = temp;
      input &gt;&gt; temp;
      pos = temp;
      input &gt;&gt; batave;
  
      Player.Additem();
  }
  
  
  
  // Write the Player data to an output stream with simple formatting
  void Player::Write(ostream &amp;out) {
      out &lt;&lt; last &lt;&lt; ", " &lt;&lt; first &lt;&lt; ": " &lt;&lt; pos;
      out &lt;&lt; fixed;
      out &lt;&lt; setprecision(3);
      out &lt;&lt; " (" &lt;&lt; batave &lt;&lt; ") ";
  }
  
  // define get/sets as needed
  double Player::getBattingAverage() { return batave;  }
  string Player::getFirstName() { return first; }
  string Player::getLastName() {  return last; }
  string Player::getFullName() {  return  first + " " + last; }
  string Player::getPosition() { return pos; }
  
  
  int main (void)
  {
      const int FNLENGTH = 100;           // use a reasonable size for filenames
      char      inputFileName[FNLENGTH];  // create buffers to store filenames
      char      outputFileName[FNLENGTH];
      ifstream  inFile;                   // create file objects for our 2 files
      ofstream  outFile;
  
      const int MAXPLAYERS = 50;
      Player    playerList[MAXPLAYERS];   // array to store player objects
      Player    currentPlayer;            // current player being retrieved from data file
      int       playerCount;              // count players as they are retrieved
      int       i;                        // loop counter
  
      // Prompt the user and open the input data file
      cout &lt;&lt; "Please enter the name of your input data file: ";
      cin &gt;&gt; inputFileName;
  
      inFile.open(inputFileName);
      if (inFile.fail()) {  // file open failed
          cout &lt;&lt; "\nError opening input file.  Cannot process player data. \nExiting Program.\n" &lt;&lt; endl;
          return 0;         // NOTE THIS IS THE ONLY TIME I ALLOW AN EMBEDDED RETURN or BREAK type exit IN A PROGRAM
      }
  
      // file opened successfully 
      playerCount = 0;
      while (!inFile.eof() &amp;&amp; playerCount &lt; MAXPLAYERS) // as long as there are lines of data to be read in read in a player
      {    
          currentPlayer.Read(inFile);
  
          //playerList[playerCount] = currentPlayer;  // store in list
          Player.Additem(currentPlayer);
          playerCount++; // count the player
      }
  
      inFile.close();
  
      // Now write the player data to the desired output file
      cout &lt;&lt; "Please enter the name of your output data file: ";
      cin &gt;&gt; outputFileName;
      outFile.open(outputFileName);  // as long as there is space on disk, this won't fail
  
      outFile &lt;&lt; "There were " &lt;&lt; playerCount &lt;&lt; " players in the input data file: \n" &lt;&lt; endl;
      for (i = 0;  i &lt; playerCount; i++) {
          playerList[i].Write(outFile);
          outFile &lt;&lt; endl;
      }
  
      outFile.close();
  
      cout &lt;&lt; "\n\nProgram 1 Complete.\nYour output is stored in the file named " &lt;&lt; outputFileName &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>I so far have tried creating an addplayer() function such as:</p>
  
  <pre><code>void Player::addplayer(string first, string last, string pos, double avg) // Stores the data in the linked list
  {
      first = first;
      last = last;
      pos = pos;
      if (avg &lt; 0) avg = -avg;  // at least try to correct
      batave = avg;
  
      if (head != NULL)
      {
          while (temp -&gt; next != NULL)
          {
              temp = temp -&gt; next;
          }
  
          temp -&gt; next = new node;
          count++;
  
          temp = temp -&gt; next;
  
          temp -&gt; item = first;
  
          temp -&gt; next = NULL;
  
      }
      else
      {
          head = new node;
          count++;
  
         // head -&gt; DOW = day; code used from other project
         // head -&gt; spent = dollars;
  
          head -&gt; next = NULL;
          temp = head;
      }
  
  }
  </code></pre>
  
  <p>So basically I'm trying to implement the first piece of code as a linked list and this is what I have so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;iomanip&gt;
  #include &lt;string&gt;
  using namespace std;
  
  
  using namespace std;
  
  struct node 
  {   string item; 
      node* next;
  };
  
  class Player
  {
      private:
           node* head;
           node* temp;
           int count;
  
          string first;    // player's first name
          string last;     // player's last name
          string pos;      // player's primary position
          double batave;   // batting average
  
      public:
          Player(); // Constructor for the class
  
          // Add player to list
          void initialize(string first, string last, string pos, double avg);
          void addplayer(string, string, string, double);
          bool isempty(); // Test if empty
  
          void print();
  
  
  
          ~Player(); // Destructor de-allocates memory used by the list.
  };
  Player::Player()
  {
      head = NULL;
  }
  
  bool isempty()
  {
  
  }
  
  void Player::addplayer(string first, string last, string pos, double avg) // Stores the data in the linked list
  {
      first = first;
      last = last;
      pos = pos;
      if (avg &lt; 0) avg = -avg;  // at least try to correct
      batave = avg;
  
      if (head != NULL)
      {
          while (temp -&gt; next != NULL)
          {
              temp = temp -&gt; next;
          }
  
          temp -&gt; next = new node;
          count++;
  
          temp = temp -&gt; next;
  
          temp -&gt; item = first;
  
          temp -&gt; next = NULL;
  
      }
      else
      {
          head = new node;
          count++;
  
         // head -&gt; DOW = day; code used from other project
         // head -&gt; spent = dollars;
  
          head -&gt; next = NULL;
          temp = head;
      }
  
  }
  
  int main(void)
  {
      ifstream  infile; // create file objects for our 2 files
      ofstream  outfile;
      string filename, filename2;
  
      cout &lt;&lt; "Hello! Please enter a valid file name (e.g. stats.txt)" &lt;&lt; endl;
      cin &gt;&gt; filename;
  
      infile.open(filename.c_str());
  
      if(!infile)
      {
          cout &lt;&lt; "We're sorry! The file specified is unavailable!" &lt;&lt; endl;
      }
      else
      {
          cout &lt;&lt; "The file has been opened!" &lt;&lt; endl &lt;&lt; endl &lt;&lt; endl;
  
          // call function
          // call function
  
  
      }
  
  
  
  
  //\\//\\//\\//\\//\\//\\//\\
      printf("\n\n\n");
      system("pause");
  }
  </code></pre>
  
  <p>Any steps of advice and code examples you guys can offer would be greatly appreciated. I've never had to "convert" code before... that's why I'm trying to start over but starting over is still difficult for me. I just want to convert from array to linked list and it's proving to be hard. 
  The program will read in a file of player stats of:</p>
  
  <pre><code>Chipper Jones 3B 0.303
  Rafael Furcal SS 0.281
  Hank Aaron RF 0.305
  </code></pre>
  
  <p>where it will sort this data and send this data to an outfile that will look like:</p>
  
  <pre><code>There were 3 players in the input data file:
  Jones, Chipper: 3B (0.303)
  Furcal, Rafael: SS (0.281)
  Aaron, Hank: RF (0.305)
  </code></pre>
  
  <p>This is what the original program does with an array implementation. I am simply trying to switch from the array to the linked list... I wanted to know the easiest route of doing this. Please help.</p>