常用类之三----最小堆实现优先队列

Priority_Queue.h
#include"MinHeap.h"
template<class T>
class Priority_Queue{
public:
Priority_Queue();
~Priority_Queue();
void Push(const T &x);
T Pop();
bool IsEmpty();
bool IsFull();
private:
MinHeap<T> *m_heap;
const int maxSize;
};

template<class T>
Priority_Queue<T>::Priority_Queue():maxSize(100){
m_heap = new MinHeap<T>(maxSize);
}

template<class T>
Priority_Queue<T>::~Priority_Queue(){
delete m_heap;
}

template<class T>
void Priority_Queue<T>::Push(const T &x){
m_heap->Insert(x);
}

template<class T>
T  Priority_Queue<T>::Pop(){
T temp;
m_heap->RemoveMin(temp);
return temp;
}

template<class T>
bool Priority_Queue<T>::IsEmpty(){
return m_heap->IsEmpty();
}

template<class T>
bool Priority_Queue<T>::IsFull(){
return m_heap->IsFull();
}

mainApp.cpp测试文件:

#include<iostream>
#include"Priority_Queue.h"
using namespace std;

void main(){
int a[5] = {3,2,1,4,5};
int i;
Priority_Queue<int> p_queue;
for(i = 0; i < 5; i++){
p_queue.Push(a[i]);
}
while(!p_queue.IsEmpty()){
cout<<p_queue.Pop()<<" ";
}
cout<<endl;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：常用类之三----最小堆实现优先队列 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)