Home > Back-end >  Turn a triple matrix addition. Code where there is a problem??
Turn a triple matrix addition. Code where there is a problem??

Time:09-27


Bool add_matrix (const TSMatrix * pM, const TSMatrix * pN, TSMatrix * pQ)
{
Int I=0, j=0, k=0;
If (pM -> m! M=pN -> | | pM -> n!=pN -> n)
return 0;
PQ -> m=pM -> m;
PQ -> n=pN -> n.
While (I len && j len) {
If (pM -> data [I] I==pN -> data [j]. J I && pM -> data [I]. J==pN -> data [j]. J && (pM -> data [I] e) + (pN -> data [j]. E)!=0) {
PQ -> data [k]. I=pM -> data [I] I;
PQ -> data [k]. J=pM -> data [I]. J.
PQ -> data [k]. E=(pM -> data [I] e) + (pN -> data [j]. E);
I++, j++ k++;
} else if (pM -> data [I] I==pN -> data [j]. J I && pM -> data [I]. J==pN -> data [j]. J && (pM -> data [I] e) + (pN -> data [j]. E)==0) {
I++ j++;
} else if (pM -> data [I] I==pN -> data [j]. J I && pM -> data [I]. J> pN -> data [j]. J) {
PQ -> data [k]=pN -> data [j];
J++ k++;
} else if (pM -> data [I] I==pN -> data [j]. J I && pM -> data [I]. J data [j]. J) {
PQ -> data [k]=pM -> data [I];
I++ k++;
} else if (pM -> data [I] I> pM -> data [j]. J I) {
PQ -> data [k]=pN -> data [j];
K++ j++;
} else if (pM -> data [I] I data [j]. J I) {
PQ -> data [k]=pM -> data [I];
K++ i++;
}
}
If (I>=pM -> len) {
While (j len) {
PQ -> data [k]=pN -> data [j];
J++ k++;
}
}
If (m>=pN -> len) {
While (I len) {
PQ -> data [k]=pM -> data [I];
I++ k++;
}
}

PQ -> len=k;
return 1;
}
  • Related