This commit is contained in:
Gašper Dobrovoljc 2024-11-29 16:15:26 +01:00
parent 56682518e8
commit eb45bf0c2b
No known key found for this signature in database
GPG Key ID: 0E7E037018CFA5A5
5 changed files with 13 additions and 7 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
.DS_Store
**/.DS_Store

1
izzivi/.idea/vcs.xml generated
View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -4,8 +4,7 @@ import java.util.ArrayList;
public class Izziv3 {
public static void main(String[] args) {
// int size = Integer.parseInt(args[0]);
int size = 20;
int size = Integer.parseInt(args[0]);
StdDraw.setCanvasSize(1500, 800);
StdDraw.setXscale(-1, size);
@ -13,7 +12,7 @@ public class Izziv3 {
CompleteBinaryTreeDrawer ctd = new CompleteBinaryTreeDrawer(size);
ctd.drawLevelorder();
ctd.drawPreorder(0);
}
}
@ -23,6 +22,8 @@ class CompleteBinaryTreeDrawer {
ArrayList<Integer> inorder;
final int size;
double xScale, yScale;
public CompleteBinaryTreeDrawer(int size) {
this.size = size;
data = new char[size];
@ -31,9 +32,12 @@ class CompleteBinaryTreeDrawer {
inorder = new ArrayList<>();
inorder(0);
xScale = size;
yScale = (int) (Math.log(size + 1) / Math.log(2)) + 1;
for (int i = 0; i < size; i++) {
data[i] = (char) ('A' + i);
x[i] = inorder.indexOf(Integer.valueOf(i));
x[i] = inorder.indexOf(i);
y[i] = (int) (Math.log(i + 1) / Math.log(2));
}
}
@ -42,14 +46,14 @@ class CompleteBinaryTreeDrawer {
if (2 * i + 1 < size) {
inorder(i * 2 + 1);
}
inorder.add(Integer.valueOf(i));
inorder.add(i);
if (2 * i + 2 < size) {
inorder(2 * i + 2);
}
}
void drawNode(int i) {
StdDraw.filledCircle(x[i], y[i], 0.1);
StdDraw.filledEllipse(x[i], y[i], xScale * 0.01, yScale * 0.02);
}
void drawEdgeToNode(int i) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

View File

@ -2,5 +2,6 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>