-
Notifications
You must be signed in to change notification settings - Fork 0
/
BTNode.java
48 lines (32 loc) · 1.15 KB
/
BTNode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/** Node of a binary tree with labels of type E */
public class BTNode<E> {
private E element;
private BTNode<E> left, right, parent;
/** default constructor */
public BTNode() { }
/** constructor with parameters */
public BTNode(E e, BTNode u, BTNode v, BTNode w) {
setElement(e);
setParent(u);
setLeft(v);
setRight(w);
}
/** accessor methods: */
public E element() { return element; }
public void setElement(E e) { element=e; }
public BTNode<E> leftChild() { return left; }
public void setLeft(BTNode<E> v) { left=v; }
public BTNode<E> rightChild() { return right; }
public void setRight(BTNode<E> v) { right=v; }
public BTNode<E> parent() { return parent; }
public void setParent(BTNode<E> v) { parent=v; }
/** methods for checking basic properties: */
public boolean isLeaf() {
return ( left==null && right==null);
}
public boolean isInternal() {
return ( left!=null || right!=null);
}
/** note that in proper binary trees one could use && instead of || */
public boolean isRoot() { return (parent==null); }
}