-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBSTNode.java
More file actions
45 lines (37 loc) · 1.05 KB
/
Copy pathBSTNode.java
File metadata and controls
45 lines (37 loc) · 1.05 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
/*
This class represents a single node in a binary search tree (BST). Each node
contains data and references to the left and right children of the node.
The <E extends Comparable<E>> in the type parameter limits the type of E to classes
that implement the Comparable interface. This makes sense for a BST since every
node has to be comparable to other nodes.
*/
public class BSTNode<E extends Comparable<E>> {
private E data;
private BSTNode<E> left, right;
// Constructor
public BSTNode(E data, BSTNode<E> left, BSTNode<E> right) {
setData(data);
setLeft(left);
setRight(right);
}
// Setter methods
public void setData(E data) {
this.data = data;
}
public void setLeft(BSTNode<E> left) {
this.left = left;
}
public void setRight(BSTNode<E> right) {
this.right = right;
}
// Getter methods
public E getData() {
return data;
}
public BSTNode<E> getLeft() {
return left;
}
public BSTNode<E> getRight() {
return right;
}
}