type
PNode=^TNode;
TNode=record
name:integer;
next:PNode;
end;
function ListReverse(head:PNode):PNode;
var
p,pPre,pcopyNex:PNode;
begin
p:=head;
pPre:=nil;
while(p <>nil) do
begin
pCopyNex:=p.next;
p.next:=pPre;
pPre:=p;
p:=pCopyNex;
end;
result:=pPre;
end;
procedure reverseDrive;
var
nd:array[0..4]of TNode;
p:Pnode;
i:integer;
begin
for i:=0 to 4 do
begin
nd[i].name:=i;
if i=4 then nd[i].next:=nil
else nd[i].next:=@nd[i+1];
end;
p:=@nd[0];
while p<>nil do
begin
showmessage(inttostr(p.name));
p:=p.next;
end;
p:=ListReverse(@nd[0]);
while p<>nil do
begin
showmessage(inttostr(p.name));
p:=p.next;
end;
end;