public class Node {
private int data;
public int getData() {
return data;
}
private Node left;
private Node right;
public Node(int d, Node l, Node r) {
data = d;
left = l;
right = r;
}
// Deep copy constructor
public Node(Node o) {
if (o == null) return;
this.data = o.data;
if (o.left != null) this.left = new Node(o.left);
if (o.right != null) this.right = new Node(o.right);
}
public List<Integer> toList() {
// Recursive code here that returns an ordered list of the nodes
}
The full class is here: https://pastebin.com/nHwXMVrd
What recursive solution could I use to return an ordered ArrayList of the Integers inside the Node? I've tried a lot of things but I have been having difficulties to find a recursive solution.