lpPoint ^. NewRight;
If (HelpPoint = CurPoint) and (HelpPointRightRange) then
HelpPoint: = HelpPoint ^. NewRight;
end;
If HelpPoint = CurPoint then SearchOpenCode: = False else SearchOpenCode: = True;
end;
procedure CreateTree;
{ --- Створення дерева частот входження ---}
begin
While SearchOpenCode do
begin
New (Root);
With Root ^ do
begin
P0: = CurPoint;
P1: = HelpPoint;
LengthBiteChain: = 0;
BiteChain: = 0;
CounterEnter: = P0 ^. CounterEnter + P1 ^. CounterEnter;
Key: = True;
P0 ^. Key: = False;
P1 ^. Key: = False;
end;
HelpPoint: = LeftRange;
While (HelpPoint ^. CounterEnter
(HelpPointNil) do HelpPoint: = HelpPoint ^. NewRight;
If HelpPoint = Nil then {додавання в кінець}
begin
Root ^. NewLeft: = RightRange;
RightRange ^. NewRight: = Root;
Root ^. NewRight: = Nil;
RightRange: = Root;
end
else
begin {вставка перед HelpPoint}
Root ^. NewLeft: = HelpPoint ^. NewLeft;
HelpPoint ^. NewLeft: = Root;
Root ^. NewRight: = HelpPoint;
If Root ^. NewLeftNil then Root ^. NewLeft ^. NewRight: = Root;
end;
end;
end;
procedure ViewTree (P: PCodElement ); p> { --- Перегляд дерева частот і присвоювання кодіровочних ланцюгів листю ---}
Var Mask, I: word;
begin
Inc (CounterBite);
If P ^. P0Nil then ViewTree ( P ^. P0);
If P ^. P1Nil then
begin
Mask: = (1 SHL (16-CounterBite));
BiteChain: = BiteChain OR Mask;
ViewTree (P ^. P1);
Mask: = (1 SHL (16-CounterBite));
BiteChain: = BiteChain XOR Mask;
end;
If (P ^. P0 = Nil) and (P ^. P1 = Nil) then
begin
P ^. BiteChain: = BiteChain;
P ^. LengthBiteChain: = CounterBite-1;
end;
Dec (CounterBite);
end;
procedure CreateCompressCode;
{ --- Обнулення змінних і запуск перегляду дерева з вершини ---}
begin
BiteChain: = 0;
CounterBite: = 0;
Root ^. Key: = False;
ViewTree (Root);
end;
procedure DeleteTree;
{ --- Видалення дерева ---}
Var P: PCodElement;
begin
CurPoint: = LeftRange;
While CurPointNil do
begin
If (CurPoint ^. P0Nil) and (CurPoint ^. P1Nil) then
begin
If CurPoint ^. NewLeft Nil then
CurPoint ^. NewLeft ^. NewRight: = CurPoint ^. NewRight;
If CurPoint ^. NewRight Nil then
CurPoint ^. NewRight ^. NewLeft: = CurPoint ^. NewLeft;
If CurPoint = LeftRange then LeftRange: = CurPoint ^. NewRight;
If CurPoint = RightRange then RightRange: = CurPoint ^. NewL...