Нужно вставить элемент после n-го элемента в односвязном списке- Pascal(Паскаль)

uses crt;

type Ptr=^count;
count=Record
   Key:integer;
   Next:ptr;
end;
var p,q,first,l:ptr;
n,m,k,i:integer;
begin
writeln('Razmer Spiska');
readln(m);
writeln('Vvedite n');
readln(n);
writeln('Vvedite k');
read(k);
new(p);
first:=p;
p^.next:=nil;
read(p^.key);
q:=p;
for i:=2 to m do
begin
     new(p);
     read(p^.key);
     p^.next:=nil;
     q^.next:=p;
     q:=p;
end;
p:=first;
i:=1;
while ((i < n - 1)and(p <> nil))do
begin
    p:=p^.next;
    inc(i);
end;
new(l);
q:= p^.next;
p^.next:=l;
l^.next:=q;
l^.key:=k;
p:=first;
while (p<>nil) do
begin
    write(p^.key,' ');
    p:=p^.next;
end;
end.
Летучий_СкилетиК вне форума	

Leave a Comment

+ 33 = 38