title: The variable I initialised as 0 randomly turns into a -1?
body: <p>I am trying to make vector based QuickSort implementation. However I ran into an out of range exception and I cannot figure out whats wrong with my code.</p>
  <pre><code>void myQuicksort(std::vector&lt;int&gt;&amp; values, int first, int last);
  
  int largest(std::vector&lt;int&gt;&amp; values)
  {
      //using Quicksort
      int first = 0;
      int last = values.size() - 1;
      myQuicksort(values, first, last);
      return values[last-1];
      
  }
  
  void myQuicksort(std::vector&lt;int&gt;&amp; values, int first, int last)
  {
      int cnt1, cnt2, pivot, Temporary;
      if (first &lt; last)
      {
          pivot = first;
          cnt1 = first;
          cnt2 = last;
          while (cnt1 &lt; cnt2)
          {
              while (values[cnt1] &lt;= values[pivot] &amp;&amp; (cnt1 &lt; last))
              {
                  cnt1++;
              }
              while (values[cnt2] &gt; values[pivot])
              {
                  cnt2--;
              }
              if (cnt1 &lt; cnt2)
              {
                  Temporary = values[pivot];
              }
          }
          Temporary = values[pivot];
          values[pivot] = values[cnt2];
          values[cnt2] = Temporary;
          myQuicksort(values, first, cnt2 - 1);
          myQuicksort(values, cnt2 - 1, last);
      }
  }
  
  int main()
  {
      std::vector&lt;int&gt; signature = { 0,21,34,55,8,13,1,1,2,3,5 };
      std::cout &lt;&lt; largest(signature)&lt;&lt;std::endl; 
  }
  </code></pre>
  <p>I used the debugger to find the &quot;first&quot; variable got reassigned as a -1. There are no clues as to why this happened. This lead to an out of range exception.</p>