public ArrayList<Object> toArrayList(ArrayList<Object> list) { if (left == null && right == null) { list.add(this); return list; } list.add(this); if (left != null) { left.toArrayList(list); } if (right != null) { right.toArrayList(list); } return list; }
public ArrayList<Object> toArrayList() { ArrayList<Object> list = new ArrayList<Object>(); if (root == null) { return list; } return root.toArrayList(list); }