主题:[请教]如何理解指针赋值操作
读入一串以"#"为结束标志的字符,统计每个字符出现的次数。
program zz_ex11_10;
type ref=^letters;
letters=record
key:char;
count:integer;
next:ref;
end;
var k:char;
sentinel,head:ref;
procedure search(x:char);
var w:ref;
begin
w:=head; {如何理解}
sentinel^.key:=x;
while w^.key<>x do w:=w^.next; {w:=w^.next如何理解}
if w<>sentinel {如何理解}
then w^.count:=w^.count+1
else begin
w:=head; {如何理解}
new(head);
with head^ do
begin
key:=x;
count:=1;
next:=w; {如何理解}
end;
end;
end;
procedure printlist(w:ref);
begin
while w<>sentinel do
begin
writeln(w^.key:2,w^.count:10);
w:=w^.next;
end;
end;
begin
new(sentinel);
with sentinel^ do
begin
key:='#';count:=0;next:=nil;
end;
head:=sentinel;
read(k);
while k<>'#' do
begin
search(k);
read(k);
end;
printlist(head);{如何理解}
end.
program zz_ex11_10;
type ref=^letters;
letters=record
key:char;
count:integer;
next:ref;
end;
var k:char;
sentinel,head:ref;
procedure search(x:char);
var w:ref;
begin
w:=head; {如何理解}
sentinel^.key:=x;
while w^.key<>x do w:=w^.next; {w:=w^.next如何理解}
if w<>sentinel {如何理解}
then w^.count:=w^.count+1
else begin
w:=head; {如何理解}
new(head);
with head^ do
begin
key:=x;
count:=1;
next:=w; {如何理解}
end;
end;
end;
procedure printlist(w:ref);
begin
while w<>sentinel do
begin
writeln(w^.key:2,w^.count:10);
w:=w^.next;
end;
end;
begin
new(sentinel);
with sentinel^ do
begin
key:='#';count:=0;next:=nil;
end;
head:=sentinel;
read(k);
while k<>'#' do
begin
search(k);
read(k);
end;
printlist(head);{如何理解}
end.