//------------------------------------------------------------------------------ int BigNumber::operator < (BigNumber x2) { TNode *temp1; TNode *temp2; int status; if (Count()<x2.Count()) return 1; else if (Count()>x2.Count()) return 0; else { temp1=root; temp2=x2.root; for (;;) { if ( (temp1->data) < (temp2->data) ) { status=1; break; } temp1=temp1->next; temp2=temp2->next; if (temp1==NULL || temp2==NULL) { status=0; break; } } return status; } }
//------------------------------------------------------------------------------ int BigNumber::operator > (BigNumber x2) { TNode *temp1; TNode *temp2; if (Count()>x2.Count()) return 1; else if (Count()<x2.Count()) return 0; else { temp1=root; temp2=x2.root; for (;;) { if (temp1->data > temp2->data) return 1; temp1=temp1->next; temp2=temp2->next; if (temp1==NULL || temp2==NULL) break; } } return 0; }
//------------------------------------------------------------------------------ BigNumber operator * (BigNumber x1, BigNumber x2) { BigNumber *array; BigNumber temp,summa; summa.AddAfter(summa.root,0); TNode *temp_x2; List list; if (x1.Count()<x2.Count()) { temp=x1; x1=x2; x2=temp; } array=new BigNumber[x2.Count()]; temp_x2=x2.last; for (int i=0;i<x2.Count();i++) { array[i]=x1.mult(temp_x2->data); array[i].AddZeroes(i); temp_x2=temp_x2->prev; } for (int i=x2.Count()-1;i>=0;i--) summa=summa+array[i]; //delete array; // return summa; return array[0]; }
//------------------------------------------------------------------------------ BigNumber operator+ (BigNumber x1, BigNumber x2) { int carry=0; int result; BigNumber temp; FIFO fifo; if (x1.Count()<x2.Count()) { temp=x1; x1=x2; x2=temp; } //temp.DeleteList(); //???????????????????????????????? TNode *temp_x1=x1.last; TNode *temp_x2=x2.last; TNode *temp_result=temp.last;//??????????????????????? for (int i=0;i<x2.Count();i++) { //Ѕлок протестирован result=temp_x1->data+temp_x2->data+carry; carry=(int)(result/1000); fifo.Push(result%1000); temp_x1=temp_x1->prev; temp_x2=temp_x2->prev; } if ( (x2.Count()==x1.Count() ) && (carry!=0) ) fifo.Push(carry); else { for (int i=x2.Count();i<x1.Count();i++) { result=temp_x1->data+carry; carry=(int)(result/1000); fifo.Push(result%1000); temp_x1=temp_x1->prev; } if (carry!=0) fifo.Push(carry); } int count=fifo.Count(); for (int i=0;i<count;i++) { if (!fifo.Pop(result)) { cout <<"Error\n"; exit(-1); } temp.AddBefore(temp.root,result); } return temp; }