Anonymous user
Huffman coding: Difference between revisions
→{{header|M2000 Interpreter}}
No edit summary |
|||
Line 3,431:
a$="this is an example for huffman encoding"
inventory queue freq
For i=1 to len(a$) {
b$=mid$(a$,i,1)
if exist(freq, b$) then Return freq, b$:=freq(b$)+1 : continue
append freq, b$:=1
}
sort ascending freq
b=stack
K=each(freq)
Line 3,479 ⟶ 3,480:
local b=array(a,1)
if type$(b)="mArray" Else {
Append decode, a$ :=array$(a, 1)
Append encode, array$(a, 1):=a$
Line 3,493 ⟶ 3,494:
{{out}}
<pre >
"
"l" 00001 0,0256
"
"
"
"
"
"
"
"n" 011 0,1026
"h" 1000 0,0513
"
"
"
"
"
"
"
" " 111 0,1538
0001010001100001111111000011111101101111110100010010110101000000000110101111101010000011111100000101110111010101101101111110100111001001001001111100011100110
this is an example for huffman encoding
157 bits Encoding/decoding worked
</pre >
|