-
Notifications
You must be signed in to change notification settings - Fork 0
/
TippKatsed.java
31 lines (23 loc) · 969 Bytes
/
TippKatsed.java
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
import ee.ut.dendroloj.Dendrologist;
import java.util.*;
public class TippKatsed {
static Tipp juhuslikPuu(int n, Random juhus) {
if (n == 0) return null;
int vasakule = juhus.nextInt(n);
return new Tipp("", juhuslikPuu(vasakule, juhus), juhuslikPuu(n - 1 - vasakule, juhus));
}
static int nummerdaKeskjärjestuses(Tipp tipp, int i) {
if (tipp == null) return i;
i = nummerdaKeskjärjestuses(tipp.v, i);
tipp.info = Integer.toString(i);
i += 1;
return nummerdaKeskjärjestuses(tipp.p, i);
}
public static void main(String[] args) {
// Dendrologist.setUIScale(2.0);
Tipp tipp = juhuslikPuu(20, new Random(42));
nummerdaKeskjärjestuses(tipp, 1);
Dendrologist.drawBinaryTree(tipp, t -> t.info, t -> t.v, t -> t.p);
// Dendrologist.drawBinaryTree(tipp, t -> t.info + " x=" + t.x, t -> t.v, t -> t.p);
}
}