title: Comparators in STL
body: <p>I am using struct minHeap to generate a min heap using priority_queue .And function comp to print numbers in reverse order using sort function given in STL . Now my doubt is that I can not use struct minHeap in function sort and can not use function comp in priorityQueue .</p>
  
  <p>I feel that function of both struct minHeap and comp is similar. Please explain me when to use structs for comaprator and when to use normal functions to behave as comparators in STL ?</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include &lt;queue&gt;
  #include &lt;stdio.h&gt;
  #include&lt;algorithm&gt;
  using namespace std;
  
  struct minHeap
  {
      bool operator()(const int a , const int b )
      {
          return a&gt;b;
      }
  };
  bool comp(int a , int b)
  {
      return a&gt;b;
  }
  
  int main()
  {
      priority_queue&lt;int , vector&lt;int&gt; , minHeap &gt; b;
  
      b.push(4);
      b.push(23);
      b.push(12);
      while(b.size()!=0)
      {
          cout &lt;&lt; b.top() &lt;&lt; " " ;
          b.pop();
      }
      cout&lt;&lt;"\n" ;
      int arr[] = {12,34, 112,12};
      sort(arr , arr+4  ,comp);
  
      for(int x= 0 ; x &lt; 4 ; x++)
      {
          cout &lt;&lt; arr[x] &lt;&lt; " " ;
      }
  }
  </code></pre>