递归方式遍历二叉树:

/*
	 * 先根序
	 */
    public static void beforeShow(Node node) {
    	if (node == null) {
    		return;
    	}
    	System.out.println(node.data);
    	beforeShow(node.left);
    	beforeShow(node.right); 
    }
    
    /*
	 * 中根序
	 */
    public static void middleShow(Node node) {
    	if (node == null) {
    		return;
    	}
    	middleShow(node.left);
    	System.out.println(node.data);
    	middleShow(node.right); 
    }
    
    /*
	 * 后根序
	 */
    public static void lastShow(Node node) {
    	if (node == null) {
    		return;
    	}
    	lastShow(node.left);
    	lastShow(node.right); 
    	System.out.println(node.data);
    }
    

  

递归遍历二叉树:

 

posted @ 2017-11-11 13:11  误入IT界的农民工  阅读(146)  评论(0编辑  收藏  举报