Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

priority queue c++

/* A priority queue maintains a set of elements. The supported operations are
insertion and, depending on the type of the queue, retrieval and removal 
of either the minimum or maximum element. Insertion and removal take 
O(logn) time, and retrieval takes O(1) time. */
priority_queue<int> q;
q.push(3); // 3
q.push(5); // 3 5
q.push(7); // 3 5 7
q.push(2); // 2 3 5 7
cout << q.top() << "
"; // 7
q.pop();
cout << q.top() << "
"; // 5
q.pop();
q.push(6);
cout << q.top() << "
"; // 6
q.pop();
 
PREVIOUS NEXT
Tagged: #priority #queue
ADD COMMENT
Topic
Name
6+9 =