D
daisyang
Unregistered / Unconfirmed
GUEST, unregistred user!
我是个初学者,编了一个HUFFMAN数,并且输出HUFFMAN编码,可是不知道什么地方
有问题,程序不能运行出来谁能帮我看看呢,在控制台写的
program dd2;
{$APPTYPE CONSOLE}
uses
SysUtils;
const n=5;
const m=9;
type
y=class
constructor inithuffman;
procedure display;
destructordo
ne;
end;
node=record
p,l,r,w:integer;
z:char;
end;
var
s:array [1..m] of node;
mark:array[1..m] of integer;
yh:y;
constructor y.inithuffman;
var
i,j,k,low1,low2,q,b,count:integer;
begin
count:=1;
for i:=1 to mdo
mark:=2;
for i:=1 to mdo
begin
s.p:=0;
s.l:=0;
s.r:=0;
s.z:='t';
end;
for i:=1 to ndo
begin
writeln('input weight');
read(s.w);
end;
s[1].z:='a';
s[2].z:='b';
s[3].z:='c';
s[4].z:='d';
s[5].z:='e';
for i:=n+1 to mdo
s.w:=1000;
low1:=s[1].w;
b:=1;
for i:=1 to ndo
begin
if s.w<low1 then
begin
low1:=s.w;
b:=i;
end;
end;
s.p:=n+1;
s[n+1].l:=b;
if b<>1 then
begin
low2:=s[1].w;
q:=1;
end
else
begin
low2:=s[2].w ;
q:=2;
end;
for i:=1 to n do
begin
if (s.w<low2) and (s.p=0) then
begin
low2:=s.w;
q:=i;
end
end;
s[q].p:=n+1;
s[n+1].w:=s[q].w+s.w;
s[n+1].r:=q;
repeat
i:=1;
while ( s.p<>0)do
i:=i+1;
low1:=s.w;
q:=i;
for j:=i+1 to mdo
//
begin
if (s[j].w<low1) and(s[j].p=0) then
begin
low1:=s[j].w;
q:=j;
end;
end;
//小循环 1
i:=i-1;
repeat
i:=i+1;
until( (s.p=0) and (i<>q));
low2:=s.w;
b:=i;
for k:=1 to mdo
begin
if (k<>q) and(s[k].w<low2)and (s[k].p=0) then
begin
low2:=s[k].w;
b:=k;
end;
end;
// 小循环2
count:=count+1;
s[n+count].w:=s[q].w+s.w;
s[n+count].l:=q;
s[n+count].r:=b;
s[q].p:=n+count;
s.p:=n+count;
writeln(s[n+count].w);
until count=4;
end;
destructor y.done;
begin
end;
procedure y.display;
var
x,i,c,f,k:integer;
number:char;
begin
i:=1;
x:=1;
writeln('intput data you are looking for');
number:='a';
while s.z<> numberdo
i:=i+1;
c:=i;
f:=s[c].p;
while (f<>0)do
begin
if s[f].l=c then
mark[x]:=1 //lefttree=1
else
mark[x]:=0;
x:=x+1;
c:=f;
f:=s[f].p;
end;
i:=m;
while mark=2do
i:=i-1;
for k:=ido
wnto 1do
write(mark[k]);
end;
{ TODO -oUser -cConsole Main : Insert code here }
begin
yh.inithuffman;
yh.display ;
yh.done;
end.
有问题,程序不能运行出来谁能帮我看看呢,在控制台写的
program dd2;
{$APPTYPE CONSOLE}
uses
SysUtils;
const n=5;
const m=9;
type
y=class
constructor inithuffman;
procedure display;
destructordo
ne;
end;
node=record
p,l,r,w:integer;
z:char;
end;
var
s:array [1..m] of node;
mark:array[1..m] of integer;
yh:y;
constructor y.inithuffman;
var
i,j,k,low1,low2,q,b,count:integer;
begin
count:=1;
for i:=1 to mdo
mark:=2;
for i:=1 to mdo
begin
s.p:=0;
s.l:=0;
s.r:=0;
s.z:='t';
end;
for i:=1 to ndo
begin
writeln('input weight');
read(s.w);
end;
s[1].z:='a';
s[2].z:='b';
s[3].z:='c';
s[4].z:='d';
s[5].z:='e';
for i:=n+1 to mdo
s.w:=1000;
low1:=s[1].w;
b:=1;
for i:=1 to ndo
begin
if s.w<low1 then
begin
low1:=s.w;
b:=i;
end;
end;
s.p:=n+1;
s[n+1].l:=b;
if b<>1 then
begin
low2:=s[1].w;
q:=1;
end
else
begin
low2:=s[2].w ;
q:=2;
end;
for i:=1 to n do
begin
if (s.w<low2) and (s.p=0) then
begin
low2:=s.w;
q:=i;
end
end;
s[q].p:=n+1;
s[n+1].w:=s[q].w+s.w;
s[n+1].r:=q;
repeat
i:=1;
while ( s.p<>0)do
i:=i+1;
low1:=s.w;
q:=i;
for j:=i+1 to mdo
//
begin
if (s[j].w<low1) and(s[j].p=0) then
begin
low1:=s[j].w;
q:=j;
end;
end;
//小循环 1
i:=i-1;
repeat
i:=i+1;
until( (s.p=0) and (i<>q));
low2:=s.w;
b:=i;
for k:=1 to mdo
begin
if (k<>q) and(s[k].w<low2)and (s[k].p=0) then
begin
low2:=s[k].w;
b:=k;
end;
end;
// 小循环2
count:=count+1;
s[n+count].w:=s[q].w+s.w;
s[n+count].l:=q;
s[n+count].r:=b;
s[q].p:=n+count;
s.p:=n+count;
writeln(s[n+count].w);
until count=4;
end;
destructor y.done;
begin
end;
procedure y.display;
var
x,i,c,f,k:integer;
number:char;
begin
i:=1;
x:=1;
writeln('intput data you are looking for');
number:='a';
while s.z<> numberdo
i:=i+1;
c:=i;
f:=s[c].p;
while (f<>0)do
begin
if s[f].l=c then
mark[x]:=1 //lefttree=1
else
mark[x]:=0;
x:=x+1;
c:=f;
f:=s[f].p;
end;
i:=m;
while mark=2do
i:=i-1;
for k:=ido
wnto 1do
write(mark[k]);
end;
{ TODO -oUser -cConsole Main : Insert code here }
begin
yh.inithuffman;
yh.display ;
yh.done;
end.