```
class Solution:
# @param root, a tree node
# @return nothing, do it in place
def flatten(self, root):
stack = []
if root:
p = root
if root.right:
stack.append(root.right)
if root.left:
stack.append(root.left)
while stack:
node = stack.pop()
if node.right:
stack.append(node.right)
if node.left:
stack.append(node.left)
p.right = node
p.left = None
p = p.right
```

As we can see, the node order in linked list is same as preorder traverse.