code: private static List<INode> preorder(INode root) {
          ArrayList<INode> result = new ArrayList<INode>();
          Deque<INode> stack = new ArrayDeque<INode>();
          stack.push(root);
          while (!stack.isEmpty()) {
              INode c = stack.pop();
  
              result.add(c);
  
              for (int i = c.getChildCount() - 1; i >= 0; i--) {
                  stack.push(c.getChildAt(i));
              }
          }
  
          return result;
      }
docs: Preorders the subtree rooted at the given node.
  
  @param root root node
  @return the converted list, empty if no elements in input