📄 multiply.h
字号:
#include<stdio.h>
#include "ADD.h"
/*
void Multiply(struct head *oprnd1, struct head *oprnd2, struct head *result)
{
struct node *n1, *n2, *rslt, *forshift;
struct head *headnode;
CreatandStore(result, 0);
n1 = oprnd1->left;
n2 = oprnd2->left;
headnode = new struct head;
for(int i=0; n2 != NULL; i++)
{
long m11, m12, m21, m22, r1, r2;
long ovrflwdgt1 = 0, ovrflwdgt2 = 0;
for(int j=0; n1 != NULL; j++)
{
// divide the 8 digits into two 4 digits to multiply
MakeNull(headnode);
m11 = n1->data/10000;
m12 = n1->data%10000;
m21 = n2->data/10000;
m22 = n2->data%10000;
r1 = m22 * m12;
r2 = m22 * m11 + m21 * m12 ;
ovrflwdgt1 = Over_flow4(r2);
r2 = r2 - ovrflwdgt1 * 10000;
r1 = r1 + r2 * 10000;
ovrflwdgt2 = Over_flow(r1);
r1 = r1 - ovrflwdgt2 * 100000000;
ovrflwdgt2 = m21 * m11 + ovrflwdgt1 + ovrflwdgt2;
rslt = new struct node;
rslt->data = r1;
InsertLeft(headnode, rslt);
if(ovrflwdgt2 != 0)
{
rslt = new struct node;
rslt->data = ovrflwdgt2;
InsertLeft(headnode, rslt);
}
// shift and add
for(int x=0; x<i+j; x++)
{
forshift = new struct node;
forshift->data = 0;
InsertRight(headnode, forshift);
}
OutPutData(headnode);
OutPutData(result);
result = BasicAdd(result, headnode);
OutPutData(result);
n1 = NextLeft(n1);
}
n2 = NextLeft(n2);
n1 = FirstLeft(oprnd1);
}
//set the sign of Multiply result
if(Sign(oprnd1) == Sign(oprnd2))
{
Assign(result, true);
}
else
{
Assign(result, false);
}
SetNoofDigits(result);
SetNoofNode(result);
OutPutData(result);
}
struct head *Multiply(struct head *headnode1, struct head *headnode2)
{
struct head *headnode3 = new struct head;
Multiply(headnode1, headnode2, headnode3);
return headnode3;
}
*/
struct head *Multiply(struct head *oprnd1, struct head *oprnd2)
{
struct node *n1, *n2, *rslt, *forshift;
struct head *result = new struct head;
struct head *headnode;
CreatandStore(result, 0);
n1 = oprnd1->left;
n2 = oprnd2->left;
headnode = new struct head;
for(int i=0; n2 != NULL; i++)
{
long m11, m12, m21, m22, r1, r2;
long ovrflwdgt1 = 0, ovrflwdgt2 = 0;
for(int j=0; n1 != NULL; j++)
{
// divide the 8 digits into two 4 digits to multiply
MakeNull(headnode);
m11 = n1->data/10000;
m12 = n1->data%10000;
m21 = n2->data/10000;
m22 = n2->data%10000;
r1 = m22 * m12;
r2 = m22 * m11 + m21 * m12 ;
ovrflwdgt1 = Over_flow4(r2);
r2 = r2 - ovrflwdgt1 * 10000;
r1 = r1 + r2 * 10000;
ovrflwdgt2 = Over_flow(r1);
r1 = r1 - ovrflwdgt2 * 100000000;
ovrflwdgt2 = m21 * m11 + ovrflwdgt1 + ovrflwdgt2;
rslt = new struct node;
rslt->data = r1;
InsertLeft(headnode, rslt);
if(ovrflwdgt2 != 0)
{
rslt = new struct node;
rslt->data = ovrflwdgt2;
InsertLeft(headnode, rslt);
}
// shift and add
for(int x=0; x<i+j; x++)
{
forshift = new struct node;
forshift->data = 0;
InsertRight(headnode, forshift);
}
result = BasicAdd(result, headnode);
n1 = NextLeft(n1);
}
n2 = NextLeft(n2);
n1 = FirstLeft(oprnd1);
}
//set the sign of Multiply result
if(Sign(oprnd1) == Sign(oprnd2))
{
Assign(result, true);
}
else
{
Assign(result, false);
}
SetNoofDigits(result);
SetNoofNode(result);
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -