不知道我是否被允许按照网站规则这样做…但我会抓住机会…请耐心等待我,我只是一个学生…… 🙂
我有一个大学任务……我很难理解课程应该做什么…我已经在三个不同的场合去找我的老师,我从他那里得到的答案根本没有帮助.无论如何,作业细节如下……
创建一个名为Tree的类,它充当节点的容器.树类应该支持以下方法.
public void add(Node parent, Node child){} — Adds a new child node to the parent node
public void removeChild(Nodeparent, Node child){} — Removes a child node from a parent.
public Node getRootNode(){} — Returns the root of the tree
public void setRoot(Node root){} — Sets the root node of the tree
public boolean contains(T data){} — Searches the tree for a given type
public void dfs(Node child){} — Performs a depth-first-search of the tree and outputs each node (indented)
public void bfs(Node child){} — Performs a breadth-first-search of the tree and outputs each node (indented)
>树类应该被参数化以处理泛型类型T,允许创建字符串,文件等的树……,例如,树 tree = new Tree< String>()
>树类应该使用邻接列表来实现树结构,并且以下面的方式定义:Ma