-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBSTNode.java
More file actions
63 lines (53 loc) · 1.56 KB
/
BSTNode.java
File metadata and controls
63 lines (53 loc) · 1.56 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
public class BSTNode {
private Record item;
private BSTNode leftChild, rightChild, parent;
// Constructor: Creates a BSTNode with the given Record
public BSTNode(Record item) {
this.item = item;
this.leftChild = null;
this.rightChild = null;
this.parent = null;
}
// Returns the Record stored in the node
public Record getRecord() {
return item;
}
// Sets the Record of the node
public void setRecord(Record d) {
this.item = d;
}
// Returns the left child of the node
public BSTNode getLeftChild() {
return leftChild;
}
// Sets the left child of the node and updates its parent
public void setLeftChild(BSTNode u) {
this.leftChild = u;
if (u != null) {
u.setParent(this); // Setting the parent of the left child
}
}
// Returns the right child of the node
public BSTNode getRightChild() {
return rightChild;
}
// Sets the right child of the node and updates its parent
public void setRightChild(BSTNode u) {
this.rightChild = u;
if (u != null) {
u.setParent(this); // Setting the parent of the right child
}
}
// Returns the parent of the node
public BSTNode getParent() {
return parent;
}
// Sets the parent of the node
public void setParent(BSTNode u) {
this.parent = u;
}
// Checks if the node is a leaf (has no children)
public boolean isLeaf() {
return leftChild == null && rightChild == null;
}
}