title: Linked List From User Input c++
body: <p>I need to get user input strings and put them into a linked list coding in c++.  I have made it so that I get user input and put it into part of the list, my problem is it only saves one into the list.  I think the problem is I only have one object in the linked list and keep overwriting it, that being said I've tried to fix it but can't find out how.  I also have to organize the list into alphabetical order but 1 step at a time.  Here is my code: </p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  using namespace std;
  
  struct Node{
      string data;
      Node *next;
  };
  
  void addToList(Node *head);
  void deleteFromList(Node *head);
  void printList(Node *head);
  
  int main(){
      bool quit = false;
      int choice;
      Node *head = new Node;
      head-&gt;next = NULL;
  
      while (!quit){
          cout &lt;&lt; "1. add to list" &lt;&lt; endl
              &lt;&lt; "2. delete from list" &lt;&lt; endl
              &lt;&lt; "3. print list" &lt;&lt; endl
              &lt;&lt; "4. quit" &lt;&lt; endl;
          cin &gt;&gt; choice;
          switch(choice){
          case 1: addToList(head);
              break;
          case 2: deleteFromList(head);
              break;
          case 3: printList(head);
              break;
          case 4: quit = true;
              break;
          default:
              cout &lt;&lt; "That is not a valid input, quitting program";
              quit = true;
          }
      }
  }
  
  void addToList(Node *head){
      bool quit = false;
      string temp;
      Node *current = new Node;
      current-&gt;next = NULL;
  
      while (!quit){
  
          cout &lt;&lt; "Enter a word(quit to stop)";
          cin &gt;&gt; temp;
  
          if (temp == "quit"){
              quit = true;
          }
          else{
              current-&gt;data = temp;
              current -&gt; next = current;
          }
      }
      return;
  }
  
  void deleteFromList(Node *head){
      string deletion;
      cout &lt;&lt; "Which value do you want to delete from the list? ";
      cin &gt;&gt; deletion;
  
      Node *prev = head;
      Node *current = head-&gt;next;
  
      while (current)
      {
          if (current-&gt;data == deletion){
              prev-&gt;next = current-&gt;next;
              delete current;
              return;
          }
          prev = current;
          current = current-&gt;next;
      }
      if (!current){
          cout &lt;&lt; "That value is not in the list" &lt;&lt; endl;
      }
  }
  
  void printList(Node *head){
      if (!head)
      {
          cout &lt;&lt; "Nothing is in the list." &lt;&lt; endl;
          return;
      }
  
      Node *current = new Node;
      current-&gt;next = head;
      while (current)  
      {
          cout &lt;&lt; current-&gt;data &lt;&lt; endl; 
          current = current-&gt;next;  
      }
  }
  </code></pre>