title: sorting names in a linked list
body: <p>I'm trying to sort names into alphabetical order inside a linked list but am getting a run time error. what have I done wrong here?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  struct node{
      string name;
      node *next;
  };
  
  node *A;
  
  void addnode(node *&amp;listpointer,string newname){
      node *temp;
      temp = new node;
      if (listpointer == NULL){
          temp-&gt;name = newname;
          temp-&gt;next = listpointer;
          listpointer = temp;
      }else{
          node *add;
          add = new node;
          while (true){
              if(listpointer-&gt;name &gt; newname){
                  add-&gt;name = newname;
                  add-&gt;next = listpointer-&gt;next;
                  break;
              }
              listpointer = listpointer-&gt;next;
          }
      }
  }
  
  int main(){
  
      A = NULL;
      string name1 = "bob";
      string name2 = "tod";
      string name3 = "thomas";
      string name4 = "kate";
      string name5 = "alex";
      string name6 = "jimmy";
      addnode(A,name1);
      addnode(A,name2);
      addnode(A,name3);
      addnode(A,name4);
      addnode(A,name5);
      addnode(A,name6);
  
      while(true){
          if(A == NULL){break;}
          cout&lt;&lt; "name is: " &lt;&lt; A-&gt;name &lt;&lt; endl;
          A = A-&gt;next;
      }
  
      return 0;
  
  }
  </code></pre>