public ListpreorderTraversal(TreeNode root) { List results = new ArrayList (); if(root == null) return results; Deque unprocessed = new ArrayDeque (); TreeNode current = root; while(current != null || !unprocessed.isEmpty()) { if(current == null) current = unprocessed.pop(); results.add(current.val); if(current.right!=null) unprocessed.push(current.right); current = current.left; } return results; }