forked from rbk-org/Java_DataStructures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree.java
More file actions
51 lines (44 loc) · 1.23 KB
/
Copy pathTree.java
File metadata and controls
51 lines (44 loc) · 1.23 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
public class Tree {
Node root =new Node();
int counter=0;
boolean res ;
private class Node {
int value;
Tree[] children = new Tree[10];
}
public boolean addChild(int val) {
if(counter>=10) return false;
Tree child = new Tree();
child.root.value = val;
this.root.children[counter++] = child;
return true;
}
public boolean contains(int val) {
// System.out.println(this.root.value);
if(this.root.value == val){
System.out.println(this.root.value);
res=true;
return true;}
if(this.counter ==0) return res ;
for (int i = 0; i <counter ; i++) {
System.out.println(res);
res= this.root.children[i].contains(val);
}
if(res){
System.out.println("res");
res = false;
return true;
}
System.out.println("here");
return res;
}
public void display() {
System.out.println(this.root.value);
if(this.root.children[0] ==null) {}
else {
for (int i = 0; i < this.root.children.length; i++) {
this.root.children[i].display();
}
}
}
}