开发者

Algorithm in C++ that deletes a node from a tree [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_运维知识库 Closed 11 years ago.

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++Builder5


I 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜