title: How to get last element of priority queue without traversing it
body: <p>I have the following priority queue:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;queue&gt;
  #include &lt;iomanip&gt;
  
  using namespace std;
  
  struct Time {
      int h; // &gt;= 0
      int m; // 0-59
      int s; // 0-59
  };
  
  class CompareTime {
  public:
      bool operator()(Time&amp; t1, Time&amp; t2)
      {
         if (t1.h &lt; t2.h) return true;
         if (t1.h == t2.h &amp;&amp; t1.m &lt; t2.m) return true;
         if (t1.h == t2.h &amp;&amp; t1.m == t2.m &amp;&amp; t1.s &lt; t2.s) return true;
         return false;
      }
  };
  
  int main()
  {
      priority_queue&lt;Time, vector&lt;Time&gt;, CompareTime&gt; pq;
  
      // Array of 4 time objects:
  
      Time t[4] = { {3, 2, 40}, {3, 2, 26}, {5, 16, 13}, {5, 14, 20}};
  
      for (int i = 0; i &lt; 4; ++i)
         pq.push(t[i]);
      while (! pq.empty()) {
         Time t2 = pq.top();
         cout &lt;&lt; setw(3) &lt;&lt; t2.h &lt;&lt; " " &lt;&lt; setw(3) &lt;&lt; t2.m &lt;&lt; " " &lt;&lt;
         setw(3) &lt;&lt; t2.s &lt;&lt; endl;
         pq.pop();
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Now in order to get the last element, I have to pop() all the elements in the queue. Is there some way by which I may retrieve just the last element of this priority queue.</p>
  
  <p>I know that it is possible to reverse the order in "CompareTime" so that the last element becomes the first. I do not want to do it as I want to pop() the elements from priority queue in the order determined by "CompareTime". But at the same time I also want the last element of the priority queue..without popping all the elements from the priority queue. Is it possible to determine the value of the last element of the priority queue.</p>
  
  <p>I am using the following gcc compiler: gcc (Ubuntu/Linaro 4.6.4-6ubuntu2) 4.6.4</p>