用十字链表解稀疏矩阵相加

Author: Date: 1995-01-27

        writeln('please enter A row and col');
        read(m,n):
        if m>n then s:=m
        else s:=m;
        new(p)'
        p^.row:=m; p^.col:=n; hm:=p cp[0]:=p;
        for i:=1 to s do
        begin
        new(p);
        p^.row=0; p^.col:=0; cp[i]:=p;
        p^.right:=p; p^.down:=p;
        p[i-1]^.next:=p
        end;
        cp[s]^.next:=hm;
        flag:=0;
        repeat
        if flag=0
        then writeln('please enter A');
        read(r,c,v);
        while(r<>rend) do{Rend为输入结束标志}
        begin
        q:=cp[r];
        while(q^.right<>cp[r]) and (q^.right^.col<c)
        do q:=q^.right;
        if q^.right^.val+v=0
        then if q^.right^.col+v=0
        then begin
        q^.right:=q^.right^.right;   a;=1
        end
        else begin
        q^.right^.val:=q^.right^.val+v;   a:=1
        end
        else begin
        new(p);  p^.row:=r;  p^.col:=c;
        p^.vla:=v:  p^.right:=q^.right;
        q^.right:=p
        end;
        q:=cp[c];
        while(q^.down<>cp[c]) and(q^.down^.row<r)
        do q:=q^.down;
        if a<>1 then begin
        p^.down:=q^.down;
        q^.down:=p
        end;
        read(r,c,v)
        end;
        if fiag=0 then r:=1.7E+38;
        writeln('please enter B')
        slse writeln('A+B=');
        flag:=1
        until(r=rend);
        end.