binnodeptr.java

来自「基于图形的二叉树工作演示程序」· Java 代码 · 共 36 行

JAVA
36
字号
// Source code example for "A Practical Introduction
// to Data Structures and Algorithm Analysis"
// by Clifford A. Shaffer, Prentice Hall, 1998.
// Copyright 1998 by Clifford A. Shaffer

// Binary tree node with pointers to children
package myBag;
public class BinNodePtr implements BinNode {
  private Object element; // Object for this node
  private BinNode left;   // Pointer to left child
  private BinNode right;  // Pointer to right child

  public BinNodePtr() {left = right = null; } // Constructor 1
  public BinNodePtr(Object val) {             // Constructor 2
    left = right = null;
    element = val;
  }

  public BinNodePtr(Object val, BinNode l, BinNode r) // Construct 3
  { left = l; right = r; element = val; }

  // Return and set the element value
  public Object element() { return element; }
  public Object setElement(Object v) { return element = v; }

  // Return and set the left child
  public BinNode left() { return left; }
  public BinNode setLeft(BinNode p) { return left = p; }

  // Return and set the right child
  public BinNode right() { return right; }
  public BinNode setRight(BinNode p) { return right = p; }

  public boolean isLeaf()  // Return true if this is a leaf node
  { return (left == null) && (right == null); }
} // class BinNodePtr

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?