You use the map for the following thing:
The key of the hashmap is a given node, and the value of the hashmap are the child nodes for the given node.
public class Tree<T> {
private Node<T> rootNode;
private HashMap<Node<T>, List<Node<T>> tree;
//and then some kind of function to go through the tree.
public void expandNode(Node<T> node) {
if (tree.get(node) == null) {
System.out.println(node);
return;
}
for(Node<T> n : tree.get(node)) {
System.out.println(node);
expandNode(n);
}
}
}
Could I make it clear how the tree works??
Answer from Juan Alberto López Cavallotti on Stack OverflowYou use the map for the following thing:
The key of the hashmap is a given node, and the value of the hashmap are the child nodes for the given node.
public class Tree<T> {
private Node<T> rootNode;
private HashMap<Node<T>, List<Node<T>> tree;
//and then some kind of function to go through the tree.
public void expandNode(Node<T> node) {
if (tree.get(node) == null) {
System.out.println(node);
return;
}
for(Node<T> n : tree.get(node)) {
System.out.println(node);
expandNode(n);
}
}
}
Could I make it clear how the tree works??
Looking at the 2 points in the list, I'm going to guess that point number 1 is the most confusing to you.
The tree itself can be parameterized. The type parameter on the tree class can be used inside an inner class that is used to create the nodes. That is to say, for the purposes of your assignment, the node class should probably be inside the Tree class so that it can use the T type parameter given to the Tree class.
That way, the tree can store anything (strings, files, Doubles, etc). The Node class simply acts as a nice way to store any type T object.
Hey I started java recently coming from python. I was taught go create nearly everything from scratch. In java, there is a node class already. Should I make my own node class or use theirs? I want make a Tree node, linklist node and binary tree node. I am confused
I'm an engineer with 15 years of experience and still don't get it. Afaik the most popular nest.js is way less powerful than spring. Also lack of multithreading. Recently see a lot of startups picking up Node. The benefits of using it are still obscured for me. Please explain!