-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyTree.java
More file actions
executable file
·43 lines (37 loc) · 992 Bytes
/
Copy pathMyTree.java
File metadata and controls
executable file
·43 lines (37 loc) · 992 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
40
41
42
43
package com.company;
public class MyTree {
private MyNode root;
MyTree (int[] inputList) {
boolean first = true;
for (int value : inputList) {
if (first) {
root = new MyNode(value);
first = false;
} else {
root.addBranch(value);
}
}
}
boolean contains(int v) {
MyNode tmpNode = this.root;
while (tmpNode != null) {
if (tmpNode.getValue() == v) {
return true;
} else {
tmpNode = tmpNode.chooseNextNode(v);
}
}
return false;
}
int count(int v) {
int result = 0;
MyNode tmpNode = this.root;
while (tmpNode != null) {
if (tmpNode.getValue() == v) {
result++;
}
tmpNode = tmpNode.chooseNextNode(v);
}
return result;
}
}