[数据结构][Tree]Search Binary Tree For Pre Order

 1 public class BinaryTreeNode
 2 {
 3     public Object data;
 4     
 5     public BinaryTreeNode leftPointer;
 6     
 7     public BinaryTreeNode rightPointer;
 8     
 9     public BinaryTreeNode(Object data)
10     {
11         this.data = data;
12     }
13     
14 }
15 
16 public class Solution
17 {
18     public void preOrder(BinaryTreeNode node)
19     {
20         if(node == null)
21         {
22             return;
23         }
24         
25         visit(node);
26         
27         if(node.leftPointer != null)
28         {
29             preOrder(node.leftPointer);
30         }
31         if(node.rightPointer != null)
32         {
33             preOrder(node.rightPointer);
34         }
35     }
36     
37     public void visit(BinaryTreeNode node)
38     {
39         System.out.println(node.data);
40     }
41     
42 }

 

posted @ 2017-10-15 21:23  StringBuilder  阅读(118)  评论(0编辑  收藏  举报