title: How to sort (custom) strings from a list
body: <p>I'm using a list structure that contains only strings. I have to sort them by length &amp;&amp; alphabetically.</p>
  
  <p>example input:</p>
  
  <blockquote>
    <p>tea, tram, top, ter, troop, true</p>
  </blockquote>
  
  <p>results in:</p>
  
  <blockquote>
    <p>tea, ter, top, tram, true, troop</p>
  </blockquote>
  
  <p>I can sort the strings on the number of characters, but I'm stuck on how to re-reorder alphabetically. The result string shows: tea,top,ter.. and they're not ordered alphabetically.
  I'm using insertion sort and a auxiliary list.</p>
  
  <pre><code>List_pointer&lt;string&gt; odd1(odd);
  auto p1 = odd1.next(odd1.begin());
  auto p2 = p1;
  if (!odd1.empty())
  {
      while (!odd1.end(p1))
      {
          p2 = odd1.previous(p1);
      while (p1 != odd1.begin() &amp;&amp; ((odd1.read(p2).size()) &gt; (odd1.read(p1).size())))
      {
      {
          auto temp = odd1.read(p1);
          odd1.write(odd1.read(p2),p1);
          odd1.write(temp,p2);
      }
          p1 = odd1.previous(p1);
          p2 = odd1.previous(p1);
      }
      p1 = odd1.next(p1);
     }
  }
  cout &lt;&lt; odd1 &lt;&lt; endl;
  </code></pre>
  
  <p>I know that the error is here: <code>while (p1 != odd1.begin() &amp;&amp; ((odd1.read(p2).size()) &gt; (odd1.read(p1).size())))</code> but I'm stuck.</p>