Huffman coding: Difference between revisions

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 {
' Print @(10); quote$(array$(a, 1));" "; a$,@(20),array(a)
Append decode, a$ :=array$(a, 1)
Append encode, array$(a, 1):=a$
Line 3,493 ⟶ 3,494:
{{out}}
<pre >
"rp" 00000 0,0256
"l" 00001 0,0256
"ct" 00010 0,0256
"ur" 00011 0,0256
"gx" 00100 0,0256
"du" 00101 0,0256
"os" 0011 0,0513
"mo" 0100 0,0513
"sm" 0101 0,0513
"n" 011 0,1026
"h" 1000 0,0513
"tc" 10010 0,0256
"pg" 100110 0,0256
"xd" 100111 0,0256
"ae" 1010 0,0769
"ia" 1011 0,0769
"fi" 1100 0,0769
"ef" 1101 0,0769
" " 111 0,1538
0001010001100001111111000011111101101111110100010010110101000000000110101111101010000011111100000101110111010101101101111110100111001001001001111100011100110
1001010001011010111110110101111101001111111011001111010010010011000001110111111000011000001111000000111100110001001010011111110101100010001100101101101100100
this is an example for huffman encoding
157 bits Encoding/decoding worked
 
</pre >
 
Anonymous user