title: C++: Fastest method to check if all array elements are equal
body: <p>What is the fastest method to check if all elements of an array(preferable integer array) are equal. Till now I have been using the following code:</p>
  
  <pre><code>bool check(int array[], int n)
  {   
      bool flag = 0;
  
      for(int i = 0; i &lt; n - 1; i++)      
      {         
          if(array[i] != array[i + 1])
              flag = 1;
      }
  
      return flag;
  }
  </code></pre>