title: My quickSort() program cannot work well, why?
body: <p>If you can help me, really thanks! Below is my code to sort vectors of numbers (of type double). The number of elements in vec is 200,000.</p>
  
  <p>The program stopped at the green line, after several seconds. The error message is that </p>
  
  <blockquote>
    <p>"Thread 1: EXC_BAD_ACCESS (code = 2, address=0x7fff5f3fffd8)".  </p>
  </blockquote>
  
  <p>just like the picture:</p>
  
  <p><a href="https://i.stack.imgur.com/7tR9N.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7tR9N.jpg" alt="enter image description here"></a></p>
  
  <pre><code>/*This is block to call quickSort*/
  void VectorDoubleSort:: sort(std::vector&lt;double&gt;&amp; vec){
        int start = 0;
        int end = vec.size() - 1;
        quickSort(vec, start, end);
  }
  
  
  
  
  /*This block to fulfill the quickSort method*/
      void VectorDoubleSort:: quickSort(std::vector&lt;double&gt;&amp; vec, int start, int end)
      {
          int pivot = (start + end) / 2;
          int smallIndex = start;
  
          if (start &lt; end) {
              double tempA = vec[start];
              vec[pivot] = tempA;
  
              for (int i = start + 1; i &lt;= end; i++) {
                  if (vec[i] &lt;= vec[start]) {
                      smallIndex += 1;
                      double tempB = vec[i];
                      vec[i] = vec[smallIndex];
                      vec[smallIndex] = tempB;
                  }
              }
  
              double tempC = vec[start];
              vec[start] = vec[smallIndex];
              vec[smallIndex] = tempC;
  
              pivot = smallIndex;
  
              quickSort(vec, start, pivot - 1);
              quickSort(vec, pivot + 1, end);
          }
      }
  </code></pre>