主题:求助--急--指针(线性链表)--删除素数单元--错误204:无效指针操作
type pointer=^node;
node=record
data:integer;
next:pointer;
end;
var p,q,head:pointer;
x:integer;
procedure delete;
var p,q:pointer;
j:integer;
k:boolean;
begin
p^.next:=head;
for j:=1 to p^.data do
if p^.data mod j=0 then k:=false;
while k=true do
begin
q:=p^.next;
p:=p^.next;
for j:=1 to p^.data do
if p^.data mod j=0 then k:=false;
[color=FF0000] end;
q^.next:=p^.next;
[color=FF00FF] dispose(p);光标停在这里(应该是附近有错!)[/color]
end;[/color]
procedure print;
var j:pointer;
begin
j:=head;
while j<>nil do
begin
write(j^.data:8);
j:=j^.next;
end;
end;
begin
write('lian biao ,-1 end:');
head:=nil;
read(x);
while x>=0 do
begin
if head=nil then
begin
new(p);
p^.data:=x;
p^.next:=nil;
q:=p;
head:=p
end
else
begin
new(p);
p^.data:=x;
p^.next:=nil;
q^.next:=p;
q:=p;
end;
read(x)
end;
delete;
print;
end.
红字错误,204错误,无效指针操作,怎么改?dispose语句不对?
node=record
data:integer;
next:pointer;
end;
var p,q,head:pointer;
x:integer;
procedure delete;
var p,q:pointer;
j:integer;
k:boolean;
begin
p^.next:=head;
for j:=1 to p^.data do
if p^.data mod j=0 then k:=false;
while k=true do
begin
q:=p^.next;
p:=p^.next;
for j:=1 to p^.data do
if p^.data mod j=0 then k:=false;
[color=FF0000] end;
q^.next:=p^.next;
[color=FF00FF] dispose(p);光标停在这里(应该是附近有错!)[/color]
end;[/color]
procedure print;
var j:pointer;
begin
j:=head;
while j<>nil do
begin
write(j^.data:8);
j:=j^.next;
end;
end;
begin
write('lian biao ,-1 end:');
head:=nil;
read(x);
while x>=0 do
begin
if head=nil then
begin
new(p);
p^.data:=x;
p^.next:=nil;
q:=p;
head:=p
end
else
begin
new(p);
p^.data:=x;
p^.next:=nil;
q^.next:=p;
q:=p;
end;
read(x)
end;
delete;
print;
end.
红字错误,204错误,无效指针操作,怎么改?dispose语句不对?