实用文档
{ cout<<\ } else{ cout<<\ list2.Display(); break; } } string choose; while (1) { cout<<\请选择运算法:\ cout<<\ /*菜单*/ cout<<\ |\ /*可以重复输入运算符,按'#'退出*/ cout<<\ |\ cout<<\ |\ cout<<\ while (1) {
cin>>choose; if (choose==\ {
list1+list2; break; } else if (choose==\ { list1*list2; break; } else if (choose==\ { return; } else { cout<<\输入有误,请重新输入!!\ continue; } } } }
标准
实用文档
/*头文件,包括长整数数据结构的定义,成员函数的定义*/
/***********************************************************/
#include
DblNode * prior; DblNode * next; };
bool IsNum(char a){ //判断字符a是否是便是数字 int s=a-'0'; if(s>=0&&s<10) return true; else return false; }
bool IsInt(string a){ //判断字符串a是否表达一串数字 bool Jud=1; int i=1; char s=a[0]; if (a==\ return false; if (s=='+'||s=='-') {} else if (s>='1'&&s<='9'){} else if (a[0]=='0'&&a[1]=='\\0') return true; else return false; while (a[i]!='\\0') { Jud=IsNum(a[i]); if (Jud==0) return false; i++; } return true; }
int JudSign(string s){ //返回数字的符号 if (s[0]=='-') return -1; else if(s[0]=='0'&&s[1]=='\\0') return 0; else return 1; }
int CtoI(char a){
标准
实用文档
int i=a-'0'; return i; }
class DblList { //定义一个双向链表类,存储任意长度的数字 private: //并可以进行标准化输出和加法,乘法。 DblNode *head, *tail; DblNode *current; int sign; public: DblList(); ~DblList(); bool CreatList(string); int GetCount(); void Insert(DblNode *); void InsertFront(DblNode *); void Clear(); void operator+(DblList &); void operator*(DblList &); DblList & operator=(DblList &); int Compare(DblList &); void Display(); };
DblList::DblList(){ head=new DblNode(); head->next=NULL; head->prior=NULL; tail=head; current=NULL; sign=0; }
DblList::~DblList(){ while (head->next!=NULL) {
current=head->next; head->next=current->next; delete current; } current=NULL; sign=0; delete head; head=NULL;
标准
//构造函数 //析构函数 //生成一个双向链表 //获取整数的长度 //从表尾插入一个结点 //从表头插入一个结点 //清除该链表 //实现两个任意整数的加法 //实现两个任意整数的乘法 //重载赋值运算符
//两个整数的绝对值比较 //任意长度整数的标准化输出 //构造函数 //析构函数 实用文档
tail=NULL; }
int DblList::GetCount(){ //返回该数字的长度(不包括符号位) current=head->next; int count=0; while (current) { count++; current=current->next; } current=NULL; return count; }
void DblList::Insert(DblNode *p){ tail->next=p; p->prior=tail; tail=p; }
void DblList::InsertFront(DblNode *q){ if (head->next==NULL) { head->next=q; q->prior=head; tail=q; } else{ q->next=head->next; head->next->prior=q; head->next=q; q->prior=head; } }
bool DblList::CreatList(string s){ bool j=IsInt(s); if (!j) return j; else{ int i=0; sign=JudSign(s); if (s[0]=='+'||s[0]=='-') i++; while (s[i]!='\\0')
标准
//从链表尾部插入一个结点 //从链表头部插入一个结点 //输入的任意长度的表示数字的字符串 //以此生成双向链表
相关推荐: