資源簡介
包含鏈表的基本操作,能夠實現多數位的大整數計算,以及十進制數和二進制數的相互轉換。

代碼片段和文件信息
#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格式不對,大整數只包含數字\n“;
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??BIGINT\BIGINT\
?????文件?????????321??2015-12-24?17:25??BIGINT\BIGINT\2power1024.txt
?????文件????????1059??2015-12-28?00:33??BIGINT\BIGINT\2的1024次二進制.txt
?????文件????????4367??2016-01-07?13:38??BIGINT\BIGINT\BIGINT.vcxproj
?????文件????????1829??2016-01-07?13:38??BIGINT\BIGINT\BIGINT.vcxproj.filters
?????文件?????????143??2015-12-09?22:25??BIGINT\BIGINT\BIGINT.vcxproj.user
?????文件???????22746??2016-01-06?22:58??BIGINT\BIGINT\BigInt.cpp
?????文件????????2065??2016-01-05?19:43??BIGINT\BIGINT\BigInt.h
?????文件???????????1??2009-08-31?02:32??BIGINT\BIGINT\ClassDiagram1.cd
?????文件????????1117??2016-01-07?13:50??BIGINT\BIGINT\ClassDiagram2.cd
?????目錄???????????0??2016-11-19?17:34??BIGINT\BIGINT\Debug\
?????文件?????????406??2016-03-20?12:32??BIGINT\BIGINT\Debug\BIGINT.exe.em
?????文件?????????472??2016-03-20?12:32??BIGINT\BIGINT\Debug\BIGINT.exe.em
?????文件?????????381??2016-03-20?12:32??BIGINT\BIGINT\Debug\BIGINT.exe.intermediate.manifest
?????文件?????????100??2016-03-20?12:32??BIGINT\BIGINT\Debug\BIGINT.lastbuildstate
?????文件????????3357??2016-03-20?12:32??BIGINT\BIGINT\Debug\BIGINT.log
?????文件?????????713??2015-12-10?00:28??BIGINT\BIGINT\Debug\BIGINT.vcxprojResolveAssemblyReference.cache
?????文件???????????0??2015-12-10?00:28??BIGINT\BIGINT\Debug\BIGINT.write.1.tlog
?????文件?????????202??2015-12-10?00:50??BIGINT\BIGINT\Debug\BIGINT_manifest.rc
?????文件???????27130??2016-03-20?12:32??BIGINT\BIGINT\Debug\BigInt.obj
?????文件???????55258??2016-03-20?12:32??BIGINT\BIGINT\Debug\CL.read.1.tlog
?????文件????????3852??2016-03-20?12:32??BIGINT\BIGINT\Debug\CL.write.1.tlog
?????文件????????3414??2016-03-20?12:32??BIGINT\BIGINT\Debug\cl.command.1.tlog
?????文件???????????2??2016-03-20?12:32??BIGINT\BIGINT\Debug\li
?????文件???????????2??2016-03-20?12:32??BIGINT\BIGINT\Debug\li
?????文件???????????2??2016-03-20?12:32??BIGINT\BIGINT\Debug\li
?????文件???????????2??2016-03-20?12:32??BIGINT\BIGINT\Debug\li
?????文件???????????2??2016-03-20?12:32??BIGINT\BIGINT\Debug\li
?????文件???????????2??2016-03-20?12:32??BIGINT\BIGINT\Debug\li
?????文件???????????2??2016-03-20?12:32??BIGINT\BIGINT\Debug\li
............此處省略142個文件信息
評論
共有 條評論