title: How to sort a string without sorting commands
body: <p>I have an assignment for one of my classes where I need to sort a string alphabetically without using any commands besides the simple ones that are already in here. Whenever I use it, it works for the most part except it will leave words like Fred &amp; Eric, or Hazel &amp; Ian (first letter's are next to each other in the alphabet). The string that is being compared to the others is set as "two" then all others are compared against it. The B string is just one that is being changed with the A string. If anyone knows why this is, that would be greatly appreciated!</p>
  
  <pre><code>for (int ct = 0; ct &lt; kh; ct++){
      hold = A[ct];
      bool pass = false;
      for (int ct2 = ct+1; ct2 &lt; kh; ct2++){
          two = A[ct2];
          if (two[0] &lt; hold[0]){
              save = A[ct2];
              A[ct2] = A[ct];
              A[ct] = save;
              hold = two;
  
              save = B[ct2];
              B[ct2] = B[ct];
              B[ct] = save;
          }
          else if (two[0] == hold[0]){
              if (two[1] &lt; hold [1]){
                  save = A[ct2];
                  A[ct2] = A[ct];
                  A[ct] = save;
                  hold = two;
  
                  save = B[ct2];
                  B[ct2] = B[ct];
                  B[ct] = save;
              }
          }
              else if (two[1] == hold[1]){
                  if (two[2] &lt; hold [2]){
                      save = A[ct2];
                      A[ct2] = A[ct];
                      A[ct] = save;
                      hold = two;
  
                      save = B[ct2];
                      B[ct2] = B[ct];
                      B[ct] = save;
              }
          }
   }
  </code></pre>
  
  <p>}</p>