- 论坛徽章:
- 0
|
int compareBigInt(BigInteger bi1,BigInteger bi2){
BigInteger p,q;
p = bi1; q = bi2;
if (bi1->sign < bi2->sign) {
return -1;
}
else if(bi1->sign > bi2->sign) {
return 1;
}
else if(bi1->sign == 0){
return 0;
}
else if(bi1->sign == 1){
while(p->next != NULL && q->next != NULL){
p=p->next;
q=q->next;
}
if(p->next==NULL&&q->next!=NULL)
return -1;
else if(p->next!=NULL&&q->next==NULL)
return 1;
else{
while(p->pred!=NULL){
if(p->value < q->value) return -1;
else if(p->value < q->value) return 1;
else {
p=p->pred;
q=q->pred;
}
}
return 0;
}
}
else if(bi1->sign == -1){
while(p->next != NULL && q->next != NULL){
p=p->next;
q=q->next;
}
if(p->next==NULL&&q->next!=NULL)
return 1;
else if(p->next!=NULL&&q->next==NULL)
return -1;
else{
while(p->pred!=NULL){
if(p->value < q->value) return 1;
else if(p->value < q->value) return -1;
else {
p=p->pred;
q=q->pred;
}
}
return 0;
}
}
} |
|