主题:建立先进先出链表中的问题?
program aa; {建立先进先出链表}
type
point=^rec;
rec=record
num:integer;
link:point;
end;
var
p,q,h:point;
n,t:integer;
begin
new(h); {建立头节点}
new(p); {有没有此句程序结果都一样,为什么呢?}
h^.num:=1;
p:=h;
t:=2;
read(n);
while n<>9999 do {建立后面的节点,以输入9999结束}
begin
new(q);
q^.num:=n;
p^.link:=q;
p:=q;
read(n);
end;
p:=h;
writeln;writeln;
while p^.num<>9999 do {输出链表数据,以p^.num<>9999作为判断条件会出错,为什么?}
begin
write(p^.num:5);
p:=p^.link;
end;
end.
type
point=^rec;
rec=record
num:integer;
link:point;
end;
var
p,q,h:point;
n,t:integer;
begin
new(h); {建立头节点}
new(p); {有没有此句程序结果都一样,为什么呢?}
h^.num:=1;
p:=h;
t:=2;
read(n);
while n<>9999 do {建立后面的节点,以输入9999结束}
begin
new(q);
q^.num:=n;
p^.link:=q;
p:=q;
read(n);
end;
p:=h;
writeln;writeln;
while p^.num<>9999 do {输出链表数据,以p^.num<>9999作为判断条件会出错,为什么?}
begin
write(p^.num:5);
p:=p^.link;
end;
end.