Skip to content

Commit

Permalink
Tweak tree layout. Add example of visualizing array-based heap.
Browse files Browse the repository at this point in the history
  • Loading branch information
FeldrinH committed Oct 25, 2023
1 parent d96b389 commit e30f734
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ee/ut/dendroloj/GenericTreeLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static <T> LayoutResult addToGraph(Graph graph, T node, Node parent, dou

int i = 0;
for (T child : children) {
LayoutResult result = addToGraph(graph, child, current, x + width, y - 2.0, getLabel, getChildren);
LayoutResult result = addToGraph(graph, child, current, x + width, y - 1.25, getLabel, getChildren);
if (i == leftReferenceNode) {
firstChildOffset = width + result.offset;
}
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/KuhjaKatsed.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import ee.ut.dendroloj.Dendrologist;

import java.util.List;

public class KuhjaKatsed {

public static void main(String[] args) {
Dendrologist.setUIScale(1.5);

List<Integer> kuhi = List.of(10, 6, 7, 3, 5, 2, 3, 9, 4, 12, 5, -7, 5, 3, 6, 6, 5, 16);
Dendrologist.drawBinaryTree(
0,
i -> String.valueOf(kuhi.get(i)),
i -> 2 * i + 1 < kuhi.size() ? 2 * i + 1 : null,
i -> 2 * i + 2 < kuhi.size() ? 2 * i + 2 : null
);

}

}
6 changes: 3 additions & 3 deletions src/test/java/TippKatsed.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public static void main(String[] args) {
new Tipp("E", new Tipp("F"), new Tipp("G")))),
null
);
tipp.v.v.p.p = tipp.v.p.v;
tipp.v.v.v = tipp.v.v.p;
tipp.v.p.p.v.p = tipp.v;
//tipp.v.v.p.p = tipp.v.p.v;
//tipp.v.v.v = tipp.v.v.p;
//tipp.v.p.v.p = tipp.v;
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);
}
Expand Down

0 comments on commit e30f734

Please sign in to comment.