CSRT-NTUA / AlgoPlus

AlgoPlus is a C++17 library for complex data structures and algorithms
https://csrt-ntua.github.io/AlgoPlus
Apache License 2.0
159 stars 20 forks source link

Added visualise for red black tree #73

Closed aveldan closed 1 month ago

aveldan commented 1 month ago

For issue #71

For an example like this

red_black_tree<int> rb({1, 2, 12, 14, 89, 3, 0, 13});
rb.visualize();

This is the dot file generated

digraph Tree {
2 [shape=circle fontcolor=black color=black]
1 [shape=circle fontcolor=black color=black]
2->1
0 [shape=circle fontcolor=black color=red]
1->0
14 [shape=circle fontcolor=black color=red]
2->14
12 [shape=circle fontcolor=black color=black]
14->12
3 [shape=circle fontcolor=black color=red]
12->3
13 [shape=circle fontcolor=black color=red]
12->13
89 [shape=circle fontcolor=black color=black]
14->89
}

And this is how it is rendered

Screenshot from 2024-07-15 12-37-13