title: how does sort function in c++ work?
body: <p>In the following code, how does the <code>sort()</code> function work?
  For example, if we have an array:</p>
  
  <pre><code>a [5] = {1,2,3,4,5};
  </code></pre>
  
  <p>and I sort it in descending order using my <code>bool cmp()</code> function,
  I want to know: How does it work, which element is <code>int a</code> and which is <code>int b</code> (the parameters in the <code>bool cmp()</code> function), when does it sort, and when does <code>bool cmp()</code> return 1 and when does it return 0?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  bool cmp (int a , int b)
  {
      return (a &gt; b );
  }
  
  int main ()
  {
      int a[100];
      int n;
      cin &gt;&gt; n;
      for (int i=0 ; i&lt;n ;i++)
          cin &gt;&gt; a[i];
  
      sort(a,a+n,cmp);
      cout &lt;&lt; endl &lt;&lt; endl;
      for (int i=0 ; i&lt;n ;i++)
          cout &lt;&lt; a[i] &lt;&lt; " ";
  
  
  
      return 0;
  }
  </code></pre>