-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNODE.java
More file actions
73 lines (61 loc) · 1.1 KB
/
NODE.java
File metadata and controls
73 lines (61 loc) · 1.1 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Vector;
public class NODE<E>
{
E val;
Vector <NODE<E>> succ;
public NODE(E v)
{
val = v;
succ = new Vector<NODE<E>>();
}
public void adjNoeud(NODE<E> id)
{
succ.add((NODE<E>) id);
}
public int nbPuitMin(NODE<E> n)
{
int lgr = n.succ.size();
int min = -1;
int tmp;
if (lgr == 0)
return 0;
for (int i = 0; i < lgr; i++)
{
tmp = this.succ.get(i).nbPuitMin(this.succ.get(i));
if (tmp != -1 && (min == -1 || min > tmp))
min = tmp;
}
if (min != -1)
return min+1;
else
return -1;
}
public int nbPuitMax(NODE<E> n)
{
int lgr = n.succ.size();
int max = -1;
int tmp;
if (lgr == 0)
return 0;
for (int i = 0; i < lgr; i++)
{
tmp = this.succ.get(i).nbPuitMax(this.succ.get(i));
if (tmp != -1 && (max == -1 || max < tmp))
max= tmp;
}
if (max != -1)
return max+1;
else
return -1;
}
public void affProf(NODE<E> n, Vector<E> res)
{
int lgr = n.succ.size();
res.add(this.val);
for (int i = 0; i<lgr; i++)
{
if (!res.contains(this.succ.get(i).val))
this.succ.get(i).affProf(this.succ.get(i),res);
}
}
}