多项式相加的链表实现

类别:编程语言 点击:0 评论:0 推荐:
多项式相加的链表实现



program ex11_5b;

type

link=^node;

node=record

zhi,xi:integer;

nxt:link;

end;

var

a,b:link;

n:integer;

procedure createfifo(var c:link);{建立多项式系数、指数链表}

var

p:link;

i:integer;

begin

new(p);

readln(p^.xi,p^.zhi);

c:=p;

for i:=1 to n-1 do

begin

new(p^.nxt);p:=p^.nxt;readln(p^.xi,p^.zhi);

end;

p^.nxt:=nil;

end;

begin

write('One : '); readln(n); createfifo(a);

write('Two : '); readln(n); createfifo(b);

write('Result is ');

while (a<>nil) and (b<>nil) do

begin

if a^.zhi>b^.zhi then

begin

if a^.xi<0 then write(#8' '#8);

write(a^.xi,'x',a^.zhi,'+');

a:=a^.nxt;

end

else

if a^.zhi

本文地址:http://com.8s8s.com/it/it26734.htm