-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyNode.java
More file actions
executable file
·39 lines (34 loc) · 842 Bytes
/
Copy pathMyNode.java
File metadata and controls
executable file
·39 lines (34 loc) · 842 Bytes
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
package com.company;
public class MyNode {
private int value;
public MyNode left;
public MyNode right;
MyNode(int v) {
value = v;
}
public int getValue() {
return value;
}
void addBranch(int x) {
if (x < this.getValue()) {
if (this.left == null) {
this.left = new MyNode(x);
} else {
this.left.addBranch(x);
}
} else {
if (this.right == null) {
this.right = new MyNode(x);
} else {
this.right.addBranch(x);
}
}
}
public MyNode chooseNextNode(int v) {
if (v < this.getValue()) {
return this.left;
} else {
return this.right;
}
}
}