📄 ddivide.h
字号:
#include<stdio.h>
#include"POW.h"
void CopyHead(struct head *headnode1, struct head *headnode2)
{
struct head *headbuffer = new struct head;
headnode1 = new struct head;
CreatandStore(headbuffer, 0);
Add(headnode2, headbuffer, headnode1);
}
void Divide(struct head *oprnd1, struct head *oprnd2, struct head *result)
{
long div1, div2, div3;
struct node *n1, *n2, *n3, *n4, *n5, *n6;
struct head *headpointer1, *headpointer2, *headpointer3, *headpointer4, *headpointer5, *buffer1, *buffer2, *ofs1, *ofs2 ;
headpointer1 = new struct head;
headpointer2 = new struct head;
headpointer3 = new struct head;
headpointer4 = new struct head;
headpointer5 = new struct head;
buffer1 = new struct head;
buffer2 = new struct head;
ofs1 = new struct head;
ofs2 = new struct head;
//set the sign of Divide result
if(Sign(oprnd1) == Sign(oprnd2))
{
Assign(result, true);
}
else
{
Assign(result, false);
}
CreatandStore(ofs1, 0);
Add(oprnd1, ofs1, ofs2);
Subtract(oprnd1, oprnd2, headpointer1);
if (Sign(headpointer1) == true)
{
cout<<"hi3"<<endl;
n1 = FirstRight(oprnd1);
n2 = FirstRight(oprnd2);
n5 = FirstRight(ofs2);
cout<<n5->data<<endl;
while(n5 != NULL)
{
div1 = n1->data / n2->data;
//cout<<div1<<endl;
cout<<"hi4"<<endl;
if(div1 >0)
{
for(int i=1; i < oprnd2->noofnode; i++ )
{
n5 = NextRight(n5);
}
cout<<n5->data<<endl;
OutPutData(oprnd2);
// average the divide result
if(NextRight(n2) != NULL)
{
cout<<"in?"<<endl;
do
{
CreatandStore(headpointer2, div1);
Multiply(headpointer2, oprnd2, buffer1);
if(buffer1->noofnode > oprnd2->noofnode)
{
div2 = (n1->data - buffer1->right->data )/n2->data;
div1 = (div1 + div2)/2;
}
}
while(div1 <= div2);
}
cout<<"hi5"<<endl;
// check whether divide is right if not make some adjust
CreatandStore(headpointer2, div1);
Multiply(headpointer2, oprnd2, buffer1);
CreatandStore(ofs1, 0);
Add(oprnd1, ofs1, headpointer3);
n3 = headpointer3->right;
for(int i=1; i < oprnd2->noofnode; i++ )
{
n3 = n3->rlink;
}
n3->rlink = NULL;
headpointer3->left = n3;
cout<<"hi6"<<endl;
Subtract(headpointer3, buffer1, buffer2);
if(Sign(buffer2)==false)
{
div1 = div1 -1;
}
n4 = new struct node;
n4->data = div1;
InsertRight(result, n4);
cout<<"hi7"<<endl;
headpointer4 = new struct head;
//substract from the oprnd1
CreatandStore(headpointer4,div1);
Multiply(oprnd2, headpointer4, headpointer5);
for(int i=0; i<oprnd1->noofnode-oprnd2->noofnode; i++)
{
n6 = new struct node;
n6->data = 0;
InsertRight(headpointer5, n6);
}
OutPutData(oprnd1);
OutPutData(headpointer5);
MakeNull(headpointer4);
Subtract(oprnd1,headpointer5, headpointer4);
OutPutData(headpointer4);
cout<<"me"<<endl;
CopyHead(oprnd1, headpointer4);
oprnd1 = headpointer4;
OutPutData(oprnd1);
}
else
{
for(int i=0; i < oprnd2->noofnode ; i++ )
{
n5 = NextRight(n5);
}
// average the divide result
do
{
div1 = n1->data*(100000000/n2->data)+n1->rlink->data/n2->data;
div3 = 100000000 % n2->data;
div3 = (div3*n1->data+n1->rlink->data)/n2->data;
div1 = div1 + div3;
if(oprnd2->right == NULL)
{
break;
}
CreatandStore(headpointer2, div1);
Multiply(headpointer2, oprnd2, buffer1);
if(buffer1->noofnode > oprnd2->noofnode)
{
div2 = (n1->data - buffer1->right->data )/n2->data;
div1 = (div1 + div2)/2;
}
}
while(div1 <= div2);
// check whether divide is right if not make some adjust
CreatandStore(headpointer2, div1);
Multiply(headpointer2, oprnd2, buffer1);
headpointer3= oprnd1;
n3 = headpointer3->right;
for(int i=0; i < oprnd2->noofnode; i++ )
{
n3 = n3->rlink;
}
n3->rlink = NULL;
headpointer3->left = n3;
Subtract(headpointer3, buffer1, buffer2);
if(Sign(buffer2)==false)
{
div1 = div1 -1;
}
n4 = new struct node;
n4->data = div1;
InsertRight(result, n4);
//substract from the oprnd1
CreatandStore(headpointer4,div1);
Multiply(oprnd2,headpointer4,headpointer5);
n6 = new struct node;
for(int i=0; i<oprnd1->noofnode-oprnd2->noofnode-1; i++)
{
n6->data = 0;
InsertRight(headpointer5, n6);
}
Subtract(oprnd1,headpointer5, headpointer4);
oprnd1 = headpointer4;
}
n1 = FirstRight(oprnd1);
cout<<n1->data<<endl;
n5 = NextRight(n5);
if(n5 == NULL )
{ cout<<"over"<<endl;}
}
}
// oprnd1 smaller than oprnd2
else
{
CreatandStore(result, 0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -