pascal中链表怎么输出?

来源:百度知道 编辑:UC知道 时间:2024/05/31 07:49:22

记住,链表也是一个记录类型,一个记录类型也是由变量来组成。所以链表的输出可以像记录那样输出。
下面是我的程序,你可以输入若干个数(一行一个),最后Ctrl+Z(文件末),回车,就可以看到程序顺序输出刚才输入的数。
type
link=^point;
point=record
num:longint;
next:link;
end;

var
head,tmp,t:link;
x:longint;

begin
new(head);
tmp:=head;
while not eof do begin
readln(x);
tmp^.num:=x;
new(t);
tmp^.next:=t;
tmp:=t;
end;
t:=tmp;
tmp:=head;
while (tmp<>nil) and (tmp<>t) do begin
writeln(tmp^.num);
tmp:=tmp^.next;
end;
end.

procedure print;
begin
repeat
writeln(p^.n);
p:=p^.next;
until p=nil;
end;