📄 hugeint.cpp.bak
字号:
}
return true;
}
Hugeint Hugeint::operator - (const long & value)
{
Hugeint res;
Hugeint h;
h = value;
res = *this - h;
return Hugeint(res);
}
Hugeint Hugeint::mul(int i)
{
Hugeint temp1;
if(i > 9 || i < 0)
return *this;
int carry = 0;
int carry1 = 0;
Hugeintnode *p = first->privor;
while(p != first)
{
temp1.insert((p->data * i) % 10 + carry + carry1);
carry = (p->data * i) /10;
if(temp1.getfirstdata() > 9)
{
temp1.upfirstdata(temp1.getfirstdata() % 10);
carry1 = 1;
}
else
carry1 = 0;
p = p->privor;
}
if(carry > 0)
temp1.insert(carry);
temp1.setheaddata(getheaddata());
while(temp1.getfirstdata() == 0)
{
if(temp1.isempty())
break;
temp1.removefirst();
}
if(temp1.isempty())
{
temp1.insert(0);
temp1.setheaddata(1);
}
return Hugeint(temp1);
}
Hugeint Hugeint::operator *(const Hugeint & h)
{
Hugeint hug;
Hugeint temm,t;
Hugeintnode *p = h.first->privor;
int i = 1;
hug = mul(p->data);
mul(p->data).makeempty();
p = p ->privor;
while(p != h.first)
{
temm = mul(p->data);
mul(p->data).makeempty();
for(int j = 0; j < i; j++)
temm.insertfromback(0);
hug = hug + temm;
p = p->privor;
i++;
}
hug.setheaddata(getheaddata() * h.getheaddata());
if(getheaddata() == 0 && h.getheaddata() ==0)
hug.setheaddata(1);
return Hugeint(hug);
}
Hugeint Hugeint::operator * (const long & value)
{
Hugeint temp;
Hugeint h ;
h = value;
temp = *this * h;
temp.setheaddata(getheaddata() * h.getheaddata());
if(getheaddata() == 0 && h.getheaddata() ==0)
temp.setheaddata(1);
return Hugeint(temp);
}
long Hugeint::chu(const Hugeint &h)
{
Hugeint temp= hugeabs(*this);
Hugeint temp2 = hugeabs(h);
if(temp2 >= temp)
return 0;
else
{
result++;
*this= *this - h;
chu(h);
}
return result;
}
Hugeint Hugeint::operator / (const Hugeint & h)
{
Hugeint temp;
Hugeint temp1= hugeabs(*this);
Hugeint temp2 = hugeabs(h);
Hugeint t = *this;
if(temp1 >= temp2)
temp = temp1.chu(temp2);
else
temp.insert(0);
temp.setheaddata(getheaddata() * h.getheaddata());
if(getheaddata() == 0 && h.getheaddata() ==0)
temp.setheaddata(1);
return Hugeint(temp);
}
Hugeint Hugeint::operator / (const long & value)
{
Hugeint h;
h = value;
Hugeint temp;
Hugeint temp1= hugeabs(*this);
Hugeint temp2 = hugeabs(h);
Hugeint t = *this;
if(temp1 >= temp2)
temp = temp1.chu(temp2);
else
temp.insert(0);
temp.setheaddata(getheaddata() * h.getheaddata());
if(getheaddata() == 0 && h.getheaddata() ==0)
temp.setheaddata(1);
return Hugeint(temp);
}
bool Hugeint::operator <= (const Hugeint & h)
{
if(getheaddata() < h.getheaddata())
return true;
else
if(getheaddata() > h.getheaddata())
return false;
else if(getheaddata() == 1 && h.getheaddata() == 1)
{
if(length() < h.length())
return true;
else if(length() > h.length())
return false;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data < q->data)
return true;
else if(p->data > q->data)
return false;
p = p->next;
q = q->next;
}
return true;
}
}
else if(getheaddata() == 0 && h.getheaddata() == 0)
{
if(length() < h.length())
return false;
else if(length() > h.length())
return true;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data < q->data)
return false;
else if(p->data > q->data)
return true;
p = p->next;
q = q->next;
}
return true;
}
}
return true;
}
bool Hugeint::operator < (const Hugeint & h)
{
if(getheaddata() < h.getheaddata())
return true;
else
if(getheaddata() > h.getheaddata())
return false;
else if(getheaddata() == 1 && h.getheaddata() == 1)
{
if(length() < h.length())
return true;
else if(length() > h.length())
return false;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data < q->data)
return true;
else if(p->data > q->data)
return false;
p = p->next;
q = q->next;
}
return false;
}
}
else if(getheaddata() == 0 && h.getheaddata() == 0)
{
if(length() < h.length())
return false;
else if(length() > h.length())
return true;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data < q->data)
return false;
else if(p->data > q->data)
return true;
p = p->next;
q = q->next;
}
return false;
}
}
return true;
}
bool Hugeint::operator == (const Hugeint & h)
{
if(getheaddata() > h.getheaddata())
return false;
else
if(getheaddata() < h.getheaddata())
return false;
else if(getheaddata() == 1 && h.getheaddata() == 1)
{
if(length() > h.length())
return false;
else if(length() < h.length())
return false;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data > q->data)
return false;
else if(p->data < q->data)
return false;
p = p->next;
q = q->next;
}
return true;
}
}
else if(getheaddata() == 0 && h.getheaddata() == 0)
{
if(length() > h.length())
return false;
else if(length() < h.length())
return false;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data > q->data)
return false;
else if(p->data < q->data)
return false;
p = p->next;
q = q->next;
}
return true;
}
}
return true;
}
bool Hugeint::operator != (const Hugeint & h)
{
return !(*this == h);
}
bool Hugeint::operator != (const long & x)
{
Hugeint h;
h = x;
return !(*this == h);
}
bool Hugeint::operator < (const long & x)
{
Hugeint h;
h = x;
if(getheaddata() < h.getheaddata())
return true;
else
if(getheaddata() > h.getheaddata())
return false;
else if(getheaddata() == 1 && h.getheaddata() == 1)
{
if(length() < h.length())
return true;
else if(length() > h.length())
return false;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data < q->data)
return true;
else if(p->data > q->data)
return false;
p = p->next;
q = q->next;
}
return false;
}
}
else if(getheaddata() == 0 && h.getheaddata() == 0)
{
if(length() < h.length())
return false;
else if(length() > h.length())
return true;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data < q->data)
return false;
else if(p->data > q->data)
return true;
p = p->next;
q = q->next;
}
return false;
}
}
return true;
}
bool Hugeint::operator <= (const long & x)
{
Hugeint h;
h = x;
if(getheaddata() < h.getheaddata())
return true;
else
if(getheaddata() > h.getheaddata())
return false;
else if(getheaddata() == 1 && h.getheaddata() == 1)
{
if(length() < h.length())
return true;
else if(length() > h.length())
return false;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data < q->data)
return true;
else if(p->data > q->data)
return false;
p = p->next;
q = q->next;
}
return true;
}
}
else if(getheaddata() == 0 && h.getheaddata() == 0)
{
if(length() < h.length())
return false;
else if(length() > h.length())
return true;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data < q->data)
return false;
else if(p->data > q->data)
return true;
p = p->next;
q = q->next;
}
return true;
}
}
return true;
}
bool Hugeint::operator == (const long & x)
{
Hugeint h;
h = x;
if(getheaddata() > h.getheaddata())
return false;
else
if(getheaddata() < h.getheaddata())
return false;
else if(getheaddata() == 1 && h.getheaddata() == 1)
{
if(length() > h.length())
return false;
else if(length() < h.length())
return false;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data > q->data)
return false;
else if(p->data < q->data)
return false;
p = p->next;
q = q->next;
}
return true;
}
}
else if(getheaddata() == 0 && h.getheaddata() == 0)
{
if(length() > h.length())
return false;
else if(length() < h.length())
return false;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data > q->data)
return false;
else if(p->data < q->data)
return false;
p = p->next;
q = q->next;
}
return true;
}
}
return true;
}
bool Hugeint::operator > (const long & x)
{
Hugeint h;
h = x;
if(getheaddata() > h.getheaddata())
return true;
else
if(getheaddata() < h.getheaddata())
return false;
else if(getheaddata() == 1 && h.getheaddata() == 1)
{
if(length() > h.length())
return true;
else if(length() < h.length())
return false;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data > q->data)
return true;
else if(p->data < q->data)
return false;
p = p->next;
q = q->next;
}
return false;
}
}
else if(getheaddata() == 0 && h.getheaddata() == 0)
{
if(length() > h.length())
return false;
else if(length() < h.length())
return true;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data > q->data)
return false;
else if(p->data < q->data)
return true;
p = p->next;
q = q->next;
}
return false;
}
}
return true;
}
bool Hugeint::operator >= (const long & x)
{
Hugeint h;
h = x;
if(getheaddata() > h.getheaddata())
return true;
else
if(getheaddata() < h.getheaddata())
return false;
else if(getheaddata() == 1 && h.getheaddata() == 1)
{
if(length() > h.length())
return true;
else if(length() < h.length())
return false;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data > q->data)
return true;
else if(p->data < q->data)
return false;
p = p->next;
q = q->next;
}
return true;
}
}
else if(getheaddata() == 0 && h.getheaddata() == 0)
{
if(length() > h.length())
return false;
else if(length() < h.length())
return true;
else
{
Hugeint t1 =hugeabs(*this);
Hugeint t2 =hugeabs(h);
Hugeintnode *p = t1.first->next;
Hugeintnode *q = t2.first->next;
while(p != t1.first && q != t2.first)
{
if(p->data > q->data)
return false;
else if(p->data < q->data)
return true;
p = p->next;
q = q->next;
}
return true;
}
}
return true;
}
Hugeint & Hugeint::operator ++()
{
*this = *this + 1 ;
return *this;
}
Hugeint & Hugeint::operator -- ()
{
*this = *this - 1;
return *this;
}
Hugeint Hugeint::operator ++ ( int )
{
Hugeint h(*this);
*this = *this + 1 ;
return h;
}
Hugeint Hugeint::operator -- (int)
{
Hugeint h(*this);
*this = *this - 1;
return h;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -