首页 > 其他 > 详细

二叉树的定义

时间:2015-01-15 10:45:37      阅读:182      评论:0      收藏:0      [点我收藏+]
/** class for nodes used in a binary tree */

package dataStructures;

public class BinaryTreeNode {
    // package visible data members
    Object element;
    BinaryTreeNode leftChild; // left subtree
    BinaryTreeNode rightChild; // right subtree

    // constructors
    public BinaryTreeNode() {
    }

    public BinaryTreeNode(Object theElement) {
        element = theElement;
    }

    public BinaryTreeNode(Object theElement, BinaryTreeNode theleftChild,
            BinaryTreeNode therightChild) {
        element = theElement;
        leftChild = theleftChild;
        rightChild = therightChild;
    }

    // accessor methods
    public BinaryTreeNode getLeftChild() {
        return leftChild;
    }

    public BinaryTreeNode getRightChild() {
        return rightChild;
    }

    public Object getElement() {
        return element;
    }

    // mutator methods 设值方法
    public void setLeftChild(BinaryTreeNode theLeftChild) {
        leftChild = theLeftChild;
    }

    public void setRightChild(BinaryTreeNode theRightChild) {
        rightChild = theRightChild;
    }

    public void setElement(Object theElement) {
        element = theElement;
    }

    // output method
    public String toString() {
        return element.toString();
    }
}

 

二叉树的定义

原文:http://www.cnblogs.com/yuwenfeng/p/4225480.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!