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

二叉树的定义

时间:2015-01-15 10:47:12      阅读:206      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!