Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
148 lines (89 loc) · 2.55 KB

File metadata and controls

148 lines (89 loc) · 2.55 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package huffmanCodeProject;
import java.io.FileReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
NewChar[] ch = Read("C:\\Users\\Itamar\\eclipse-workspace\\tree\\src\\huffmanCodeProject\\txt.txt");
System.out.println("have an array");
for(int i = 0; i<allCh.length; i++) {
System.out.println(allCh[i].amunt+" ch = "+allCh[i].ch);
}
Node root = new Node(100);
System.out.println("len = "+allCh.length);
char[] p = new char[0];
root.insert(allCh,p);
root.print();
}//main****************************************************
public static NewChar[] Read(String path) throws IOException {
@SuppressWarnings("resource")
FileReader fr = new FileReader(path);
NewChar[] ch = new NewChar[0];
int i;
int len = 0;
while((i = fr.read()) != -1) {
len++;
char Char = (char)i;
ch = func(Char, ch);
}
ch = Sort(ch);
System.out.println("\nsorted!!");
ch = precentegculc(ch, len);
System.out.println("\nprecenteg culculted");
for(int j = 0; j<ch.length; j++) {
System.out.println(ch[i].amunt);
}
return ch;
}
public static NewChar[] func(char Char, NewChar[] ch) {
NewChar[] nch = new NewChar[ch.length + 1];
for(int i = 0; i<ch.length; i++) {
nch[i] = ch[i];
}
nch[nch.length -1].ch = Char;
return nch;
}
public static NewChar[] culc(char[] ch) {
NewChar[] allCh = new NewChar[1];
allCh[0] = new NewChar(' ');
for(int i = 0; i<ch.length; i++) {
for(int j = 0; j<allCh.length; j++) {
if(ch[i] == allCh[j].ch) {
allCh[j].amunt++;
j = allCh.length;
}else if(j == allCh.length-1) {
allCh = AddNewChar(ch[i], allCh);
}
}
}
return allCh;
}
public static NewChar[] AddNewChar(char chToAdd, NewChar[] ch) {
NewChar[] newch = new NewChar[ch.length + 1];
for(int i = 0; i<ch.length; i++) {
newch[i] = ch[i];
}
NewChar ncToAdd = new NewChar(chToAdd);
newch[newch.length -1] = ncToAdd;
return newch;
}
public static NewChar[] Sort(NewChar[] arr) {
NewChar temp;
for (int i = 1; i < arr.length; i++) {
for (int j = i; j > 0; j--) {
if (arr[j].amunt > arr [j - 1].amunt) {
temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
}
}
return arr;
}
public static NewChar[] precentegculc(NewChar[] nch){
int sum = nch.length;
for(int i = 0; i<nch.length; i++) {
nch[i].amunt = nch[i].amunt/sum;
}
return nch;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.