title: priority_queue - delete not a top elements
body: <p>I have priority_queue. My function delete not very rational in terms of memory consumption and time.
  I've seen similar themes, but they did not help me.</p>
  <p><a href="https://stackoverflow.com/questions/19467485/c-priority-queue-removing-element-not-at-top">How to remove element not at top from priority_queue?</a></p>
  <p><a href="https://stackoverflow.com/questions/3076163/stl-priority-queue-deleting-an-item">STL Priority Queue - deleting an item</a></p>
  <p>How i can delete elements on log( n ).</p>
  <p>My function:</p>
  <h1>1</h1>
  <pre><code>void deleteFromTimeQueue(const K&amp; key)
              {
                  std::priority_queue&lt;Record&lt;K&gt;, std::vector&lt;Record&lt;K&gt;&gt;, Comparator&lt;K&gt;&gt; tmpTimeQueue_;
  
                  while (timeQueue_.size() &gt; 0)
                  {
                      Record&lt;K&gt; it = timeQueue_.top();
  
                      if (it.getKey() == key)
                      {
                          timeQueue_.pop();
                          break;
                      }
                      tmpTimeQueue_.push(it);
                      timeQueue_.pop();
                  }
  
                  while (tmpTimeQueue_.size() &gt; 0)
                  {
                      Record&lt;K&gt; it = tmpTimeQueue_.top();
                      timeQueue_.push(it);
                      tmpTimeQueue_.pop();
                  }
              }
  </code></pre>
  <p>How i can delete elements whitout <strong>tmpTimeQueue_</strong>?</p>
  <h1>2</h1>
  <pre><code>void deleteFromTimeQueue(const K&amp; key)
          {
              std::priority_queue&lt;Record&lt;K&gt;, std::vector&lt;Record&lt;K&gt;&gt;, Comparator&lt;K&gt;&gt; tmpTimeQueue_;
  
              while (timeQueue_.size() &gt; 0)
              {
                  Record&lt;K&gt; it = timeQueue_.top();
  
                  if (it.getKey() == key)
                  {
                      timeQueue_.pop();
                      continue;
                  }
                  tmpTimeQueue_.push(it);
                  timeQueue_.pop();
              }
              timeQueue_.swap(tmpTimeQueue_);
          }
  </code></pre>
  <p><strong>What number better 1 or 2?</strong></p>