public void flatten(Node root) {
        if (root == null) {
            return;
        }
        Stack<Node> stack = new Stack<>();
        stack.push(root);
        Node prev = null;
        while (!stack.isEmpty()) {
            Node node = stack.pop();
            if (prev != null) {
                prev.right = node;
            }
            prev = node;
            if (node.right != null) {
                stack.push(node.right);
            }
            if (node.left != null) {
                stack.push(node.left);
            }
            node.left = null;
            node.right = null;
        }
    }
Date 10/06/2016
@author Tushar Roy

Given a binary tree, flatten it to a linked list in-place in preorder traversal.

Time complexity O(n)

https://leetcode.com/problems/flatten-binary-tree-to-linked-list/
src/com/interview/tree/FlattenLinkListToBinaryTreePreorder.java