forked from bzdgn/data-structures-in-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNaryNode.java
More file actions
36 lines (28 loc) · 691 Bytes
/
NaryNode.java
File metadata and controls
36 lines (28 loc) · 691 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
package ds_010_trees;
public class NaryNode<T extends Comparable<T>> {
public T data;
public final NaryNode<T>[] children;
int size = 0;
@SuppressWarnings("unchecked")
public NaryNode(T data, int numOfChildren) {
this.data = data;
this.children = (NaryNode<T>[])new NaryNode[numOfChildren];
}
public void addChild(T data, int numOfChildren) {
if(!isFull()) {
children[size++] = new NaryNode<>(data, numOfChildren);
}
}
public NaryNode<T> getChild(T data) {
for(NaryNode<T> result : children) {
if(result.data.equals(data)) {
return result;
}
}
return null;
}
// trivial
public boolean isFull() {
return size == children.length;
}
}