很多函数都出现了两次,以destory为例,想只出现一次应该怎么改
#include <iomanip>
#include <iostream>
using namespace std;
template <class T>
class LeftistNode{//左式堆
public:
T key; // 关键字(键值)
int npl; // 零路经长度(Null Path Length)
LeftistNode *left; // 左孩子
LeftistNode *right; // 右孩子
LeftistNode(T value, LeftistNode *l, LeftistNode *r):
key(value), npl(0), left(l),right(r) {}
};
template <class T>
class LeftistHeap {
private:
LeftistNode<T> *mRoot; // 根结点
void destroy(LeftistNode<T>* &heap);
public:
LeftistHeap();//...
~LeftistHeap();//...
void destory();
//...
template <class T>
void LeftistHeap<T>::destroy(LeftistNode<T>* &heap)
{
if (heap==NULL)
return ;
if (heap->left != NULL)
destroy(heap->left);
if (heap->right != NULL)
destroy(heap->right);
delete heap;
}
template <class T>
void LeftistHeap<T>::destroy()
{
destroy(mRoot);
}
翻翻过去那场雪
扬帆大鱼
相关分类