Izziv 3
This commit is contained in:
parent
56682518e8
commit
eb45bf0c2b
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1 @@
|
||||
.DS_Store
|
||||
**/.DS_Store
|
||||
|
1
izzivi/.idea/vcs.xml
generated
1
izzivi/.idea/vcs.xml
generated
@ -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>
|
@ -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) {
|
||||
|
BIN
izzivi/src/izziv3/n13preorder.png
Normal file
BIN
izzivi/src/izziv3/n13preorder.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 163 KiB |
1
naloge/naloga1/.idea/vcs.xml
generated
1
naloge/naloga1/.idea/vcs.xml
generated
@ -2,5 +2,6 @@
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
Loading…
x
Reference in New Issue
Block a user