Sorting a vector of strings by the first letter in non-ascii order in C++
<p>I have a text file with a list of words.</p>

<p>I used <code>ifstream</code> to read these words into a <code>vector</code> and now I am trying to sort them in an order similar to:</p>

<pre><code>A a B b C c [...]
</code></pre>

<p>I tried to implement this using a third for loop inside of a bubble search algorithm to look at the first character of each word (I know this is far from the most efficient way especially if I was using a large data set)</p>

<p>And then check whether the letter and the next letter were uppercase or lowercase and switching if the uppercase letter was the same letter as the current letter, but this didn't seem to work.</p>

<pre><code>void bubble_Sort (vector &lt;string&gt; &amp; words)
{
  for (unsigned i = words.size(); i &gt;= 2; --i)
  {
    for (unsigned k = 0; k + 1 &lt; i; k++)
    {
      int hi = k+1;
      string temp1 = words[hi];
      string temp2 = words[k];
      int smallsize = words[hi].size();
      int smallprecedence = 0;

      if (words[k].size() &lt; words[hi].size())
        smallsize = words[k].size();

      for (unsigned j = 0; j &lt; smallsize; j++)
      {
        if (temp1[j] &gt;= 'A' &amp;&amp; temp1[j] &lt;= 'Z')
        {
          if (temp2[j] &gt;='a' &amp;&amp; temp2[j] &lt;= 'z')
          {
            char lowercase1 = temp1[j] + 32;
            if (lowercase1 == temp2[j])
            {
              string temp = words[k];
              words[k] = words[hi];
              words[hi] = temp;
              break;
            }
          }

          else if (temp2[j] &gt;= 'A' &amp;&amp; temp2[j] &lt;= 'Z')
          {
            if (temp1[j] &lt; temp2[j])
            {
              string temp = words[k];
              words[k] = words[hi];
              words[hi] = temp;
              break;
            }
          }
        }

        if (temp1[j] &gt;= 'a' &amp;&amp; temp1[j] &lt;= 'z')
        {
          if (temp2[j] &gt;= 'A' &amp;&amp; temp2[j] &lt;= 'Z')
          {
            char uppercase1 = temp1[j] - 32;
            if (uppercase1 &lt; temp2[j])
            {
              string temp = words[k];
              words[k] = words[hi];
              words[hi] = temp;
              break;
            }
          }

          else if (temp2[j] &gt;= 'a' &amp;&amp; temp2[j] &lt;= 'z')
          {
            if (temp1[j] &lt; temp2[j])
            {
              string temp = words[k];
              words[k] = words[hi];
              words[hi] = temp;
              break;
            }
          }
        }

        else if (temp1[j] == temp2[j] &amp;&amp; temp1.size() &lt; temp2.size())
          ++smallprecedence;
      }

      if (smallprecedence == smallsize)
      {
        string temporary = words[k];
        words[k] = words[hi];
        words[hi] = temporary;
      }
    }
  }
}
</code></pre>