mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 21:24:53 +08:00
feat: Add the section of Top-K problem (#551)
* Add the section of Top-K problem * Update my_heap.py * Update build_heap.md * Update my_heap.py
This commit is contained in:
@ -13,16 +13,6 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
/* Expose the underlying storage of the priority_queue container */
|
||||
template <typename T, typename S, typename C> S &Container(priority_queue<T, S, C> &pq) {
|
||||
struct HackedQueue : private priority_queue<T, S, C> {
|
||||
static S &Container(priority_queue<T, S, C> &pq) {
|
||||
return pq.*&HackedQueue::c;
|
||||
}
|
||||
};
|
||||
return HackedQueue::Container(pq);
|
||||
}
|
||||
|
||||
/* Find an element in a vector */
|
||||
template <typename T> int vecFind(const vector<T> &vec, T ele) {
|
||||
int j = INT_MAX;
|
||||
@ -217,6 +207,16 @@ template <typename TKey, typename TValue> void printHashMap(unordered_map<TKey,
|
||||
}
|
||||
}
|
||||
|
||||
/* Expose the underlying storage of the priority_queue container */
|
||||
template <typename T, typename S, typename C> S &Container(priority_queue<T, S, C> &pq) {
|
||||
struct HackedQueue : private priority_queue<T, S, C> {
|
||||
static S &Container(priority_queue<T, S, C> &pq) {
|
||||
return pq.*&HackedQueue::c;
|
||||
}
|
||||
};
|
||||
return HackedQueue::Container(pq);
|
||||
}
|
||||
|
||||
/* Print a Heap (PriorityQueue) */
|
||||
template <typename T, typename S, typename C> void printHeap(priority_queue<T, S, C> &heap) {
|
||||
vector<T> vec = Container(heap);
|
||||
|
||||
Reference in New Issue
Block a user