发布网友 发布时间:2022-04-21 17:35
共1个回答
热心网友 时间:2024-09-09 16:08
program project1;
type
point=^node;
node=record
data:longint;
next:point;
end;
var
i,n,e:longint;
p,q,head,last:point;
begin
write('Input the number count:');
readln(n);
i:=1;
new(head);
read(e);
head^.data:=e;
head^.next:=nil;
last:=head;
q:=head;
while i<n do
begin
inc(i);
read(e);
new(p);
q^.next:=p;
p^.data:=e;
p^.next:=nil;
last:=p;
q:=last
end;
//建立链表
q:=head;
while q^.next<>nil do begin
write(q^.data,' ');
q:=q^.next;
end;
write(q^.data);
//输出
readln;
readln
end.
之后是子过程删除,在以z为头的链表中搜索第一个n,如果找到则删去,返回值为1,否则返回0
function delete(n:longint;var z:point):longint;
var
t,s:point;
begin
t:=z;
while (t^.next<>nil) and (t^.data<>n) do begin
s:=t;
t:=t^.next;
end;
if t^.data<>n then exit(0);
s^.next:=t^.next;
dispose(t);
exit(1)
end;
最后的插入,在以zz为头的链表第w个的前面插入nn元素,函数返回值正常是0,如果w超过了链表的长度,函数返回链表的长度
function insert(w,nn:longint;var zz:point):longint;
var
d:longint; v,vp,vs:point;
begin
v:=zz;
for d:=1 to w do
if v^.next=nil then exit(d)
else begin
vp:=v;
v:=v^.next;
end;
new(vs);
vs^.data:=nn;
vp^.next:=vs;
vs^.next:=v;
exit(0)
end;
全是自己上机测试过的,纯手打,要给分啊 (百度百科也发过了)
参考资料:全是自己上机测试过的,纯手打,要给分啊
热心网友 时间:2024-09-09 16:08
program project1;
type
point=^node;
node=record
data:longint;
next:point;
end;
var
i,n,e:longint;
p,q,head,last:point;
begin
write('Input the number count:');
readln(n);
i:=1;
new(head);
read(e);
head^.data:=e;
head^.next:=nil;
last:=head;
q:=head;
while i<n do
begin
inc(i);
read(e);
new(p);
q^.next:=p;
p^.data:=e;
p^.next:=nil;
last:=p;
q:=last
end;
//建立链表
q:=head;
while q^.next<>nil do begin
write(q^.data,' ');
q:=q^.next;
end;
write(q^.data);
//输出
readln;
readln
end.
之后是子过程删除,在以z为头的链表中搜索第一个n,如果找到则删去,返回值为1,否则返回0
function delete(n:longint;var z:point):longint;
var
t,s:point;
begin
t:=z;
while (t^.next<>nil) and (t^.data<>n) do begin
s:=t;
t:=t^.next;
end;
if t^.data<>n then exit(0);
s^.next:=t^.next;
dispose(t);
exit(1)
end;
最后的插入,在以zz为头的链表第w个的前面插入nn元素,函数返回值正常是0,如果w超过了链表的长度,函数返回链表的长度
function insert(w,nn:longint;var zz:point):longint;
var
d:longint; v,vp,vs:point;
begin
v:=zz;
for d:=1 to w do
if v^.next=nil then exit(d)
else begin
vp:=v;
v:=v^.next;
end;
new(vs);
vs^.data:=nn;
vp^.next:=vs;
vs^.next:=v;
exit(0)
end;
全是自己上机测试过的,纯手打,要给分啊 (百度百科也发过了)
参考资料:全是自己上机测试过的,纯手打,要给分啊
热心网友 时间:2024-09-09 16:08
program project1;
type
point=^node;
node=record
data:longint;
next:point;
end;
var
i,n,e:longint;
p,q,head,last:point;
begin
write('Input the number count:');
readln(n);
i:=1;
new(head);
read(e);
head^.data:=e;
head^.next:=nil;
last:=head;
q:=head;
while i<n do
begin
inc(i);
read(e);
new(p);
q^.next:=p;
p^.data:=e;
p^.next:=nil;
last:=p;
q:=last
end;
//建立链表
q:=head;
while q^.next<>nil do begin
write(q^.data,' ');
q:=q^.next;
end;
write(q^.data);
//输出
readln;
readln
end.
之后是子过程删除,在以z为头的链表中搜索第一个n,如果找到则删去,返回值为1,否则返回0
function delete(n:longint;var z:point):longint;
var
t,s:point;
begin
t:=z;
while (t^.next<>nil) and (t^.data<>n) do begin
s:=t;
t:=t^.next;
end;
if t^.data<>n then exit(0);
s^.next:=t^.next;
dispose(t);
exit(1)
end;
最后的插入,在以zz为头的链表第w个的前面插入nn元素,函数返回值正常是0,如果w超过了链表的长度,函数返回链表的长度
function insert(w,nn:longint;var zz:point):longint;
var
d:longint; v,vp,vs:point;
begin
v:=zz;
for d:=1 to w do
if v^.next=nil then exit(d)
else begin
vp:=v;
v:=v^.next;
end;
new(vs);
vs^.data:=nn;
vp^.next:=vs;
vs^.next:=v;
exit(0)
end;
全是自己上机测试过的,纯手打,要给分啊 (百度百科也发过了)
参考资料:全是自己上机测试过的,纯手打,要给分啊