PDA

View Full Version : تبدیل c++ به c



dokhtareironi
یک شنبه 05 آذر 1385, 13:31 عصر
من در تبدیل کد ضرب و جمع اسپارس به مشکل دارم (از c++ به c ) کسی میتونه کمکم

کنه؟

میخوام این برنامه رو تبدیل کنم به ضرب 2 تا ماتریس اسپارس به صورت ساده در زبان c





void Sparse :: MulSparse( Sparse a, Sparse b )
{
if( a.Col != b.Row )
{
cout << "\n*** ERROR !!! Zarbe 2 Matris Emkan Pazir Nist ***";
Row = 0;
Col = 0;
Terms = 0;
return;
}
if( ( a.Terms == Max ) || ( b.Terms == Max ) )
{
cout << "*** ERROR !!! Yek Fazaye Khali Dar Matris 'A' Ya 'B' Lazem Ast ***";
Row = 0;
Col = 0;
Terms = 0;
return;
}
Sparse d;
d.FastTranspose( b );
int currRowIndex = 0, LastInResult = -1, currRowBegin = 0, currRowA = a.Data[0].row;
a.Data[a.Terms].row = a.Row;
d.Data[b.Terms].row = b.Col;
d.Data[b.Terms].col = -1;
int sum = 0;
while( currRowIndex < a.Terms )
{
int currColB = d.Data[0].row;
int currColIndex = 0;
while( currColIndex <= b.Terms )
{
if( a.Data[currRowIndex].row != currRowA )
{
if( StoreSum( sum, LastInResult, currRowA, currColB ) )
{
Row = 0;
Col = 0;
Terms = 0;
cout << "\n *** ERROR !!! ***";
return;
}
else
sum = 0;
currRowIndex = currRowBegin;
while ( d.Data[currColIndex].row == currColB )
currColIndex++;
currColB = d.Data[currColIndex].row;
}
else if( d.Data[currColIndex].row != currColB)
{
if( StoreSum( sum, LastInResult, currRowA, currColB ) )
{
Row = 0;
Col = 0;
Terms = 0;
cout << "\n *** ERROR !!! ***";
return;
}
else
sum = 0;
currRowIndex = currRowBegin;
currColB = d.Data[currColIndex].row;
}
else switch( compare( a.Data[currRowIndex].col, d.Data[currColIndex].col ) )
{
case '<' :
currRowIndex++;
break;
case '=' :
sum += a.Data[currRowIndex].value * d.Data[currColIndex].value;
currRowIndex++;
currColIndex++;
break;
case '>' :
currColIndex++;
}
}
while( a.Data[currRowIndex].row == currRowA )
currRowIndex++;
currRowBegin = currRowIndex;
currRowA = a.Data[currRowIndex].row;
}
Row = a.Row;
Col = b.Col;
Terms = LastInResult + 1;
}