包含链表的基本操作,能够实现多数位的大整数计算,以及十进制数和二进制数的相互转换。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-11-19 17:34 BIGINT
目录 0 2016-11-19 17:34 BIGINTBIGINT
文件 321 2015-12-24 17:25 BIGINTBIGINT2power1024.txt
文件 1059 2015-12-28 00:33 BIGINTBIGINT2的1024次二进制.txt
文件 4367 2016-01-07 13:38 BIGINTBIGINTBIGINT.vcxproj
文件 1829 2016-01-07 13:38 BIGINTBIGINTBIGINT.vcxproj.filters
文件 143 2015-12-09 22:25 BIGINTBIGINTBIGINT.vcxproj.user
文件 22746 2016-01-06 22:58 BIGINTBIGINTBigInt.cpp
文件 2065 2016-01-05 19:43 BIGINTBIGINTBigInt.h
文件 1 2009-08-31 02:32 BIGINTBIGINTClassDiagram1.cd
文件 1117 2016-01-07 13:50 BIGINTBIGINTClassDiagram2.cd
目录 0 2016-11-19 17:34 BIGINTBIGINTDebug
文件 406 2016-03-20 12:32 BIGINTBIGINTDebugBIGINT.exe.embed.manifest
文件 472 2016-03-20 12:32 BIGINTBIGINTDebugBIGINT.exe.embed.manifest.res
文件 381 2016-03-20 12:32 BIGINTBIGINTDebugBIGINT.exe.intermediate.manifest
文件 100 2016-03-20 12:32 BIGINTBIGINTDebugBIGINT.lastbuildstate
文件 3357 2016-03-20 12:32 BIGINTBIGINTDebugBIGINT.log
文件 713 2015-12-10 00:28 BIGINTBIGINTDebugBIGINT.vcxprojResolveAssemblyReference.cache
文件 0 2015-12-10 00:28 BIGINTBIGINTDebugBIGINT.write.1.tlog
文件 202 2015-12-10 00:50 BIGINTBIGINTDebugBIGINT_manifest.rc
文件 27130 2016-03-20 12:32 BIGINTBIGINTDebugBigInt.obj
文件 55258 2016-03-20 12:32 BIGINTBIGINTDebugCL.read.1.tlog
文件 3852 2016-03-20 12:32 BIGINTBIGINTDebugCL.write.1.tlog
文件 3414 2016-03-20 12:32 BIGINTBIGINTDebugcl.command.1.tlog
文件 2 2016-03-20 12:32 BIGINTBIGINTDebuglink-cvtres.read.1.tlog
文件 2 2016-03-20 12:32 BIGINTBIGINTDebuglink-cvtres.write.1.tlog
文件 2 2016-03-20 12:32 BIGINTBIGINTDebuglink.10696-cvtres.read.1.tlog
文件 2 2016-03-20 12:32 BIGINTBIGINTDebuglink.10696-cvtres.write.1.tlog
文件 2 2016-03-20 12:32 BIGINTBIGINTDebuglink.10696.read.1.tlog
文件 2 2016-03-20 12:32 BIGINTBIGINTDebuglink.10696.write.1.tlog
文件 2 2016-03-20 12:32 BIGINTBIGINTDebuglink.11652-cvtres.read.1.tlog
............此处省略142个文件信息
#include“BigInt.h“
//---------------构造函数
template
inline BigInt::BigInt(int jinzhi=10) //初始化默认为十进制
{
last=new Node();
last->next=last;
last->prev=last;
sys=jinzhi;
max_digit=0;
}
//---------------拷贝函数
template
inline BigInt::BigInt(const BigInt & original)
{
sys=original.sys; //这步非常重要,不然返回值生成对象的sys处于非定义状态
max_digit=original.max_digit;
last=new Node();
BigInt::NodePointer lastPtr = last
origPtr = original.last
ptr;
while(origPtr->next != original.last)
{
origPtr = origPtr->next;
lastPtr->next =new BigInt::Node(origPtr->data.coeforigPtr->data.digit);
ptr=lastPtr;
lastPtr = lastPtr->next;
lastPtr->prev=ptr;
}
lastPtr->next=last;
last->prev=lastPtr;
}
//---------------析构函数
template
inline BigInt::~BigInt() //尾空节点也是要释放的,再调用时注意初始化
{
BigInt::NodePointer currPtr = last->next
nextPtr;
while (currPtr != last)
{
nextPtr =currPtr->next;
delete currPtr;
currPtr=nextPtr;
}
delete currPtr;
max_digit=0; //把最大数位也置0
}
//---------------赋值函数(BigInt to BigInt)
template
inline const BigInt & BigInt::operator=(const BigInt & rightHandSide)
{
sys=rightHandSide.sys;
if (this != &rightHandSide) //不等的话才将左值清空初始化
{
this->~BigInt(); //有个疑惑,为什么析构后会把成员变量初始化?(即调用了构造函数)
last=new Node();
max_digit=rightHandSide.max_digit; //一定要在析构完后赋值
BigInt::NodePointer lastPtr = last
origPtr = rightHandSide.last
ptr;
while(origPtr->next != rightHandSide.last)
{
origPtr = origPtr->next;
lastPtr->next =new BigInt::Node(origPtr->data.coeforigPtr->data.digit);
ptr=lastPtr;
lastPtr = lastPtr->next;
lastPtr->prev=ptr;
}
lastPtr->next=last;
last->prev=lastPtr;
}
return *this;
}
//--------------赋值函数(string to BigInt)
template
inline const BigInt & BigInt::operator=(const string str)
{
this->~BigInt();
last=new Node();
last->next=last;
last->prev=last;
for(int i=str.length()-1j=1;i>=0;--i++j)
{
char ch=str[i];
int num;
if(judgeInt(ch)) //判断是否整数
{num=ch-‘0‘;}
else
{
cout<<“string格式不对,大整数只包含数字
“;
this->~BigInt();
last=new Node();
last->next=last;
last->prev=last;
break;
}
pushFirst(numj);
}
max_digit=str.length();
digitSort();
bigIntFirstClearZero(); //标上数位并除首部0
return *this;
}
//--------------判空函数
template
inline bool BigInt::empty()const
{
return max_digit==0 ? true : false; //max_digit=0代表只有一个last空节点
}
//---------------首部插入
template
inline void BigInt::pushFirst(const CoefType &value1int value2=10)
{
BigInt::NodePointer newPtr=new Node(value
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-11-19 17:34 BIGINT
目录 0 2016-11-19 17:34 BIGINTBIGINT
文件 321 2015-12-24 17:25 BIGINTBIGINT2power1024.txt
文件 1059 2015-12-28 00:33 BIGINTBIGINT2的1024次二进制.txt
文件 4367 2016-01-07 13:38 BIGINTBIGINTBIGINT.vcxproj
文件 1829 2016-01-07 13:38 BIGINTBIGINTBIGINT.vcxproj.filters
文件 143 2015-12-09 22:25 BIGINTBIGINTBIGINT.vcxproj.user
文件 22746 2016-01-06 22:58 BIGINTBIGINTBigInt.cpp
文件 2065 2016-01-05 19:43 BIGINTBIGINTBigInt.h
文件 1 2009-08-31 02:32 BIGINTBIGINTClassDiagram1.cd
文件 1117 2016-01-07 13:50 BIGINTBIGINTClassDiagram2.cd
目录 0 2016-11-19 17:34 BIGINTBIGINTDebug
文件 406 2016-03-20 12:32 BIGINTBIGINTDebugBIGINT.exe.em
文件 472 2016-03-20 12:32 BIGINTBIGINTDebugBIGINT.exe.em
文件 381 2016-03-20 12:32 BIGINTBIGINTDebugBIGINT.exe.intermediate.manifest
文件 100 2016-03-20 12:32 BIGINTBIGINTDebugBIGINT.lastbuildstate
文件 3357 2016-03-20 12:32 BIGINTBIGINTDebugBIGINT.log
文件 713 2015-12-10 00:28 BIGINTBIGINTDebugBIGINT.vcxprojResolveAssemblyReference.cache
文件 0 2015-12-10 00:28 BIGINTBIGINTDebugBIGINT.write.1.tlog
文件 202 2015-12-10 00:50 BIGINTBIGINTDebugBIGINT_manifest.rc
文件 27130 2016-03-20 12:32 BIGINTBIGINTDebugBigInt.obj
文件 55258 2016-03-20 12:32 BIGINTBIGINTDebugCL.read.1.tlog
文件 3852 2016-03-20 12:32 BIGINTBIGINTDebugCL.write.1.tlog
文件 3414 2016-03-20 12:32 BIGINTBIGINTDebugcl.command.1.tlog
文件 2 2016-03-20 12:32 BIGINTBIGINTDebugli
文件 2 2016-03-20 12:32 BIGINTBIGINTDebugli
文件 2 2016-03-20 12:32 BIGINTBIGINTDebugli
文件 2 2016-03-20 12:32 BIGINTBIGINTDebugli
文件 2 2016-03-20 12:32 BIGINTBIGINTDebugli
文件 2 2016-03-20 12:32 BIGINTBIGINTDebugli
文件 2 2016-03-20 12:32 BIGINTBIGINTDebugli
............此处省略142个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)