blob: 7b498037c5416fe250c7de6935bbc6a0c2623f06 (
plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
Tests for the splay tree.
See https://en.wikipedia.org/wiki/Splay_tree
The test build a splay tree with the node given as argument, then display the
representation using the dot syntax.
$ tests --splay_tree \
> --help
Start the tests
--add Add an element in the tree
--del Remove an element from the tree
--get Get an element from the tree
-help Display this list of options
--help Display this list of options
The root is the latest inserted node:
$ tests --splay_tree \
> --add 5 \
> --add 3
digraph G {
leaf_0 [shape=point]
"3" -> leaf_0
"3" -> "5"
leaf_1 [shape=point]
"5" -> leaf_1
leaf_2 [shape=point]
"5" -> leaf_2
}
$ tests --splay_tree \
> --add 3 \
> --add 5
digraph G {
"5" -> "3"
leaf_0 [shape=point]
"3" -> leaf_0
leaf_1 [shape=point]
"3" -> leaf_1
leaf_2 [shape=point]
"5" -> leaf_2
}
Collecting an element in the tree will push this node at the root:
$ tests --splay_tree \
> --add 1 \
> --add 2 \
> --add 3 \
> --get 2
digraph G {
"2" -> "1"
leaf_0 [shape=point]
"1" -> leaf_0
leaf_1 [shape=point]
"1" -> leaf_1
"2" -> "3"
leaf_2 [shape=point]
"3" -> leaf_2
leaf_3 [shape=point]
"3" -> leaf_3
}
$ tests --splay_tree \
> --add 1 \
> --add 2 \
> --add 3 \
> --add 4 \
> --get 1
digraph G {
leaf_0 [shape=point]
"1" -> leaf_0
"1" -> "3"
"3" -> "2"
leaf_1 [shape=point]
"2" -> leaf_1
leaf_2 [shape=point]
"2" -> leaf_2
"3" -> "4"
leaf_3 [shape=point]
"4" -> leaf_3
leaf_4 [shape=point]
"4" -> leaf_4
}
Removing an element from the tree modify the structure
$ tests --splay_tree \
> --add 1 \
> --add 2 \
> --add 3 \
> --del 2
digraph G {
leaf_0 [shape=point]
"1" -> leaf_0
"1" -> "3"
leaf_1 [shape=point]
"3" -> leaf_1
leaf_2 [shape=point]
"3" -> leaf_2
}
|