I'm working on a project to create a tree with more than 2 child nodes. I get that when creating a binary tree, we can just create a left node and a right node to act as children, but when I've looked online for help in creating a tree, every solution I've found talks about creating a binary tree. I understand that part of creating a tree means you need to create an array or arraylist of children nodes, but I don't understand how I'm going to put data into that array or how I'm going to 'connect' the array of children nodes to my parent node?
Here's the code I have at the moment. I know it's not a lot, but I'm struggling just starting this project.
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
{
}
How and where do I start this process of connecting my children nodes to my parent/root node?