-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgDescriptionWriter.java
More file actions
87 lines (80 loc) · 2.5 KB
/
Copy pathgDescriptionWriter.java
File metadata and controls
87 lines (80 loc) · 2.5 KB
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
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class gDescriptionWriter {
String givenString;
String graphDescriptionFileName;
Huffman treeInfo;
int prevwe;
int flag = 0;
public gDescriptionWriter(String org, String dot, Huffman h) {
givenString = org;
graphDescriptionFileName = dot;
treeInfo = h;
}
public void generateDescriptionFile(String fname) {
if (treeInfo.sizeOfHuffManTree > 1) {
node n = treeInfo.root;
try (PrintWriter o = new PrintWriter(new BufferedWriter(new FileWriter(fname)))) {
o.println("digraph g {");
writerMethod(n, o);
o.println("}");
} catch (IOException e) {
System.out.println(e);
}
}
}
public void writerMethod(node n, PrintWriter o) {
if (!treeInfo.checkIfLeafOrNot(n)) {
if (n.left != null) {
String tempVariable2 = "";
char tempVariable = n.left.character;
if (tempVariable != '\0' && tempVariable != ' ' && tempVariable != '"' && tempVariable != '\n')
tempVariable2 = "\\n " + tempVariable;
else if (tempVariable == ' ')
tempVariable2 = "\\n blank";
else if (tempVariable == '"')
tempVariable2 = "\\n \\\"";
else if (tempVariable == '\n')
tempVariable2 = "\\n /n";
if (prevwe == n.weight) {
flag++;
}
if (prevwe == n.weight && flag > 2) {
System.out.println("Graph Generation will not be correct");
} else {
o.println(
" \"" + "\\n" + n.weight + "\" -> \"" + "\\n" + n.left.weight + tempVariable2
+ "\" [color=red, label=0]");
writerMethod(n.right, o);
}
prevwe = n.weight;
}
if (n.right != null) {
String tempVariable2 = "";
char tempVariable = n.right.character;
if (tempVariable != '\0' && tempVariable != ' ' && tempVariable != '"' && tempVariable != '\n')
tempVariable2 = "\\n " + tempVariable;
else if (tempVariable == ' ')
tempVariable2 = "\\n blank";
else if (tempVariable == '"')
tempVariable2 = "\\n \\\"";
else if (tempVariable == '\n')
tempVariable2 = "\\n /n";
if (prevwe == n.weight) {
flag++;
}
if (prevwe == n.weight && flag > 2) {
System.out.println("Graph Generation will not be correct");
} else {
o.println(
" \"" + "\\n" + n.weight + "\" -> \"" + "\\n" + n.left.weight + tempVariable2
+ "\" [color=red, label=0]");
writerMethod(n.right, o);
}
prevwe = n.weight;
}
}
}
}