资源简介
包含链表的基本操作,能够实现多数位的大整数计算,以及十进制数和二进制数的相互转换。

代码片段和文件信息
#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个文件信息
相关资源
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
- c++ 画图(14Qt-XPS)
- c++多边形交并差运算
评论
共有 条评论