Algorithm in C++ that deletes a node from a tree [closed]
I need help with tree structures and nodes
template <class T> class tBST {
protected:
tBSTNode<T>* root;
template <class T> class tBSTNode{
protected:
T data;
tBSTNode<T>* left;
tBSTNode<T>* right;
I want to create an algorithm named root->Delete(T data); on the class tBSTNode, that, when you call the function from the class tBST from root, it deletes the same input that I put (T data).
Can someone give me a hand? I'm very stucked with this
I'm making it in C++ with C++Builder5I don't think you're understanding what templates do. The type given to the template specifies the type of the template.
The type isn't a member of the template.
Given tBST<int>
and tBST<double>
, neither contains an int or double, they are new types.
If you're trying to implement a method to delete data within the T type. You simply call delete on T, then whatever classes will be used as types for the template, must implement the delete method.
If you're trying to delete a T from a branch in the node, then you need to create destructors in the template tBSTnode
that delete either child. Then you set that item to null in its parent node.
精彩评论