码迷,mamicode.com
首页 > 其他好文 > 详细

线索二叉树

时间:2016-11-28 20:27:02      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:pass   zha   debug   null   adt   import   min   thread   log   

package cn.firstflag.crm.service;

import jxl.common.Logger;

/**
 * 
 * @author zhanmin.zheng
 *
 */
public class ThreadTree {
    
    private Logger log = Logger.getLogger(getClass());
    
    private Integer childFlag = 0;
    
    private Integer threadFlag = 1;
    
    public class Node <T> {
        
        private T data;
        
        private Integer leftFlag = childFlag;
        
        private Integer rightFlag = childFlag;
        
        private Node leftChildren;
        
        private Node rightChildren;

        public Node() {
            super();
        }

        public Node(T data) {
            super();
            this.data = data;
        }
        
    }
    
    static Node pre = null;
    
    public void create(Node node) {
        
        if (node == null) return;
        if (node.leftChildren == null) {
            node.leftFlag = 1;
        }
        if (node.rightChildren == null) {
            node.rightFlag = 1;
        }
        
        if (node.leftFlag == 1) {
            node.leftChildren = pre;
        } 
        
        if (pre != null && pre.rightFlag ==1) {
            pre.rightChildren = node;
        }
        pre = node;
        create(node.leftChildren);
        create(node.rightChildren);
        
    }
    
    public Node foreach(Node node) {
        
        while (node.leftFlag == 1) {
            node = node.leftChildren;
        }
        
        while (node.rightFlag == 1) {
            log.debug("pass " + node.data);
            node =node.rightChildren;
        }
        return node;
    }
}

 

线索二叉树

标签:pass   zha   debug   null   adt   import   min   thread   log   

原文地址:http://www.cnblogs.com/sz-zzm/p/6110506.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!