Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
4
Indexable
Never
#ifndef BINARYTREE_H
#define BINARYTREE_H
using namespace std;

template<class T>
struct NodeType {
    T key;
    NodeType<T> *left;
    NodeType<T> *right;
};

template<class T>
class BinaryTree {
public:
    BinaryTree();
    ~BinaryTree();
    void freeNodes(NodeType<T>* &tree);
    void insert(T &key);
    void insertNode(NodeType<T>* &tree, T &key);
    void deleteItem(T &key);
    void Delete(NodeType<T>* tree, T &item);
    void retrieve(NodeType<T>* &tree, T &item, bool &found) const;
    void getRetrieve(T &key);
    void getPredecessor(NodeType<T>* &tree, T &item);
    void deleteNode(NodeType<T>* &tree);
    void preOrder() const;
    void preOrderPrint(NodeType<T>* tree) const;
    void inOrder() const;
    void inOrderPrint(NodeType<T>* tree) const;
    void postOrder() const;
    void postOrderPrint(NodeType<T>* tree) const;
    int getLength() const;
    int getNumSingleParent();
    int getNumSingleParentHelper(NodeType<T>* tree);
    int getNumLeafNodes() const;
    int getNumLeafNodesHelper(NodeType<T>* tree) const;
    //void getSumOfSubTrees(T &item) const;
    //int getSumOfSubTreesHelper(NodeType<T>* tree, T &item, int count) const;
private:
    NodeType<T> *root;
    int length;
};

#endif