词条 | 静态链表 |
释义 | § 基本资料 链表大家都知道吧,我就不废话了......给个程序吧... program static_link_list(input,output); const maxl=10; type elem=record num,next:integer; end; tlist=array【0..maxl】of elem; var list:tlist; num,place,head,av:integer; ch:char; function get_node(var av:integer):integer; begin get_node:=av; if av<>-1 then av:=list【av】.next; end; procedure disp_node(var av:integer;k:integer); begin list【k】.next:=av; av:=k; end; procedure init(var av:integer); var i:integer; begin for i:=0 to maxl-1 do list.next:=i+1; list【maxl】.next:=-1; av:=0; end; procedure print(head:integer); begin head:=list【head】.next; while head<>-1 do begin write(list【head】.num,' '); head:=list【head】.next; end; writeln; end; procedure insert(head,num,place:integer;var av:integer); var j,x:integer; begin j:=0; while (head<>-1)and(j<place-1) do begin inc(j); head:=list【head】.next; end; if (head=-1)or(j>place-1) then begin writeln('Input Error!'); exit; end; x:=get_node(av); if x=-1 then begin writeln('List has been full!'); exit; end; list【x】.num:=num; list【x】.next:=list【j】.next; list【j】.next:=x; end; procedure del(var av:integer;head,place:integer); var j,k:integer; begin j:=0; while (list【head】.next<>-1)and(j<place-1) do begin inc(j); head:=list【head】.next; end; if (list【head】.next=-1)or(j>place-1) then begin writeln('Input Error!'); exit; end; k:=list【head】.next; list【head】.next:=list【list【head】.next】.next; disp_node(av,k); end; begin init(av); head:=get_node(av); list【head】.next:=-1; readln(ch); while ch<>'E' do begin case ch of 'I':begin readln(num,place); insert(head,num,place,av); end; 'D':begin readln(place); del(av,head,place); end; 'P':print(head); else writeln('Input Error!'); end; readln(ch); end; end. § 相关链接 |
随便看 |
百科全书收录594082条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。