title: C++ Add to linked list in sorted order
body: <p>Hi I have a linked list using structs. Right now I got it to add every element at the end. However I'd like to add each element in sorted order based on the ID. The struct has two elements: string name, and long ID.</p>
  
  <pre><code>node* temp = new node;
  temp-&gt;name = nameRead;
  temp-&gt;id = idRead;
  
  //check if first item, if so add as head
  if(head == NULL)
  {
      head = temp;
  }
  else
  {
     node* temp2 = head;
     while(temp2-&gt;next != NULL)
     {
        temp2 = temp2-&gt;next;
     }
     temp2-&gt;next = temp;
  }
  </code></pre>