/**
 * Definition for binary tree
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public List<Integer> preorderTraversal(TreeNode root) {
        Stack<TreeNode> stack = new Stack<TreeNode>();
        TreeNode node = root;
        List<Integer> result = new ArrayList<Integer>();
        while ((stack.empty() != true) || (node != null)) {
            if (node != null) {
                result.add(node.val);
                if (node.right != null) {
                    stack.push(node.right);
                }
                node = node.left;
            } else {
                node = stack.pop();
            }
        }
        return result;
    }
}

@@ -15,16 +15,18 @@
 ion for 
+a 
 binary t
@@ -28,16 +28,22 @@
 ary tree
+ node.
 %0A * publ
@@ -168,23 +168,16 @@
 * %7D%0A */%0A
-public 
 class So
@@ -291,49 +291,11 @@
 ack%3C
-TreeNode%3E();%0A        TreeNode node = root
+%3E()
 ;%0A  
@@ -341,20 +341,49 @@
 ist%3C
-Integer%3E()
+%3E();%0A        TreeNode p = root
 ;%0A
+        %0A
     
@@ -397,40 +397,29 @@
 le (
-(
+!
 stack.
-e
+isE
 mpty() 
-!= true) %7C%7C (node
+%7C%7C p
  != 
@@ -423,17 +423,16 @@
 != null)
-)
  %7B%0A     
@@ -442,20 +442,17 @@
     if (
-node
+p
  != null
@@ -486,65 +486,16 @@
 add(
-node
+p
 .val);%0A
-                if (node.right != null) %7B%0A    
     
@@ -517,20 +517,17 @@
 ck.push(
-node
+p
 .right);
@@ -547,37 +547,13 @@
     
-%7D%0A                node = node
+p = p
 .lef
@@ -592,20 +592,17 @@
         
-node
+p
  = stack
@@ -625,32 +625,41 @@
     %7D%0A        %7D%0A
+        %0A
         return r

Update BinaryTreePreorderTraversal.java