48
правок
Изменения
Pseudocode1 bugfix
'''void''' defineSegments(letters: '''char'''[m], probability: '''double'''[m]):
'''Segment''' segment[m]segment
'''double''' l = 0
'''for''' i = 1 0 '''to''' m- 1
segment[letters[i]].left = l
segment[letters[i]].right = l + probability[i]
'''double''' ArithmeticCodingarithmeticCoding(s: '''char'''[n]): defineSegments(letters, probability)
'''double''' left = 0
'''double''' right = 1
'''for''' i = 0 '''to''' n-1
'''char''' symb = s[i]
'''double''' newRight = left + (right - left) * segment[symb].right''<font color=green>// segment {{---}} массив, заполненный в результате выполнения метода defineSegments</font>''
'''double''' newLeft = left + (right - left) * segment[symb].left
left = newLeft