我正在开发一个项目来创建一个具有 2 个以上子节点的树。我知道在创建二叉树时,我们可以只创建一个左节点和一个右节点来充当子节点,但是当我在网上寻找创建树的帮助时,我找到的每个解决方案都在谈论创建二叉树树。我知道创建树的部分意味着您需要创建子节点的数组或数组列表,但我不明白如何将数据放入该数组或如何“连接”数组子节点到我的父节点?
这是我目前拥有的代码。我知道这不是很多,但我刚开始这个项目就很挣扎。
class Node
{
public int data; //data for storage
public Node[] children;//array will keep children
public Node parent;//parent to start the tree
public Node(, int data)//constructor will store data and children(I think?)
{
}
}
public class Tree //main class will implement everything in Node
{
}
我如何以及从哪里开始将我的子节点连接到我的父/根节点的过程?