title: Extracting last element of a priority_queue
body: <p>I'm using a std::priority_queue to write an algorithm that computes the Distance Function of a data-set on a 3D grid. After having initialized the queue I'd like to store in a separate variable the last element, just like you do with std::queue.back() but, of course, this is not possible with priority queues, so my work-around is the following:</p>
  
  <pre><code>CellQueue q; //this is the actual priority_queue
  
  //...
  //initialization
  //...
  
  Cell* last = 0;
  CellQueue dummy(q);
  while (!dummy.empty()) {
      last = dummy.top();
      dummy.pop();
  }
  </code></pre>
  
  <p>Of course there is a better way to solve this problem, so I'd be very glad if someone could show it to me.</p>
  
  <p>Thanks,</p>
  
  <p>Federico</p>
  
  <hr>
  
  <p>EDIT</p>
  
  <p>@Sam @Dietmar The algorithm to compute the distance function (DF) works in this way: you fill the priority_queue with the cells of the grid that contain at least one point of the data-set and you order them by distance (which at this step is zero) in increasing order. Then, for each element of the queue, you visit the neighbors and for each neighbor you compute the distance with respect to its parent. Now, for efficiency reasons I'd like to compute the DF only on a narrow band around the data-set. So in order to stop this process after having visited the 3rd ring neighborhood, I have to keep track of the last element of the current ring.</p>