c++ 大整数乘法

本文介绍了一种使用C++实现大整数乘法的方法,通过定义链表结构存储大整数,并实现了输入、输出、插入、拷贝构造函数等基本操作。此外,还重载了加法和乘法运算符,使得大整数可以进行加法和乘法计算。
摘要由CSDN通过智能技术生成

 #include<iostream.h>
#include<stdio.h>
#include<math.h>

struct Dnode{
 int data;
 Dnode *prv;
 Dnode *next;
};

class Bigint
{
public:
 Dnode *head,
  *p,
  *q,
  *r;
public:
 void input();
 void shaw();
 void clear();
 void insert(int n);
 void output(Bigint &b);
 Bigint(){
  head=new Dnode;
  head->prv=NULL;
      head->next=NULL;
  head->data=NULL;
 }
 Bigint(Bigint &a);
 ~Bigint(){
    r=this->head;
  while(r!=head){
   p=r;
   delete p;
   r=r->next;
  } 
 }
 friend Bigint operator +(Bigint& a,Bigint& b);
 friend Bigint operator *(Bigint& a,Bigint& b);
 Bigint operator = (const Bigint &BigNum);
 
};

 

Bigint::Bigint(Bigint &a){  //拷贝构造
 this->head=new Dnode;
 p=head;
 q=a.head;
 r=a.head->next;
 this->head->next=NULL;
 this->head->prv=NULL;
 
 while(r!=a.head){
  Dnode *b=new Dnode;
  b->next=head;
  b->data=r->data;
  p->next=b;
  b->prv=p;
  head->prv=b

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值