I've been trying to implement a heap into my program. It seems to me that heaps are the same as binary trees. Is this the case with all heaps such as min heap and max heap since all that is being done is a traversal through the tree putting the largest/smallest node to the top?
Also, I've read that using 1-D arrays are only beneficial when we have a complete binary tree. If we don't have a complete binary tree, it would be more beneficial to use class that is a friend class to another? Why is that? Such as:
template<class T> class BT; // forward declartion -> added at edit
template<class T>
class BTNode{
friend class BT<T>; // not sure why we need two classes
private:
T data;
BTNode<T> *leftChild; // what is the benefit of making a object Node?
BTNode<T> *rightChild;
};
template<class T>
class BT{
private:
BTNode<T> *root; // what is the benefit of having this root in another class?
};
Thank you in advance.