title: Simultaneous minimum and maximum
body: <p>I've tried to implement an algorithm that would search for both minimum and maximum elements in  a given array, and used the ideas from Cormen's <em>Introduction to Algorithms</em>. My code compiles and starts working, outputs the generated random array and then does nothing for a really long time.
  Why could that be?</p>
  
  <p>The code is this:</p>
  
  <pre><code>// fast min and max --cormen exercise 1.cpp: entry point
  //implemented from a verbal description in cormen's book, p 243
  
  #include "stdafx.h"
  #include &lt;vector&gt;
  #include &lt;ctime&gt;
  #include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  
  struct min_and_max
  {
      int min, max;
  };
  
  
  min_and_max find_min_and_max(std::vector&lt;int&gt;&amp; A)
  {
      int n = A.size();
      int min, max;
      if (n%2 == 1)
          min = max = A[0];
      if (n%2 == 0)
          if (A[0] &lt; A[1])
          {
              min = A[0];
              max = A[1];
          }
          else
          {
              min = A[1];
              max = A[0];
          }
      for(int i = 2; i &lt; A.size(); (i + 2))
      {
          if (A[i] &lt; A[i+1])
          {
              if (min &gt; A[i])
                  min = A[i];
              if (max &lt; A[i+1])
                  max = A[i+1];
          }
          else
          {
              if (min &gt; A[i+1])
                  min = A[i+1];
              if (max &lt; A[i])
                  max = A[i];
          }
      }
      min_and_max result;
      result.min = min;
      result.max = max;
  
      return result;
  }
  
  int main()
  {
      std::srand(std::time(0));
      std::vector&lt;int&gt; A(10);
      for (auto i = 0; i &lt; A.size(); i++)
          {
              A[i] = rand() % 1000;
              std::cout &lt;&lt; A[i] &lt;&lt; " ";           
          }
      std::cout &lt;&lt; std::endl; //IT GOES AS FAR AS THIS
      std::cout &lt;&lt; "The array has been analyzed; its' minimum is " &lt;&lt; find_min_and_max(A).min &lt;&lt; "and its' maximum is " &lt;&lt; find_min_and_max(A).max &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>