运行的时候会崩溃,然后我调试的时候有出现cannot find bounds of current fuction,会出现截图的那种情况,貌似栈中指针找不到函数
源码
#include
#include
using namespace std;
class linklist
{
private:
struct node {
int data;
node *prev,*next;
node():prev(NULL),next(NULL){} //初始化
~node(){}
};
node *head,*tail; //头和尾指针
int currentlength; //表长
public:
linklist(); //构造函数
~linklist() {clear(); delete head; delete tail;} //析构函数
void clear(); //清除各结点的函数
void show();
void setup();
linklist operator+(const linklist &r1) const ;
};
linklist::linklist()
{
head=new node;
head->next=tail=new node;
tail->prev=head;
currentlength=0;
}
void linklist::setup()
{
int x;
int i=0;
cout<<"请输入位数小于1000000的数"<
cin>>x;
node *p,*q;
head=p=new node;
while(x<1000000){
if(x==0) break;
q=new node;
++i;
q->data=x%int (pow(10,i));
x=int (x/pow(10,i));
p->next=q;
q->prev=p;
p=q;
}
p->next=tail;
tail->prev=p;
tail->next=NULL;
head->prev=NULL;
currentlength=i;
}
void linklist::clear()
{
node *p,*q;
p=head->next;
head->next=tail;
tail->prev=head;
while(p!=tail){
q=p->next;
delete p;
p=q;
}
currentlength=0;
}
void linklist::show()
{
node *q;
q=tail->prev;
while(q!=head){
cout<data;
q=q->prev;
}
}
linklist linklist::operator+(const linklist &r1) const
{
linklist tmp;
node *p,*p1,*p2,*q;
tmp.head=p=new node;
p1=r1.head->next;
p2=head->next;
int carry=0;
while(1){
q=new node;
if((p1->data+p2->data)>=10) {q->data=(carry+p1->data+p2->data-10); carry=1; }
else {q->data=carry+p1->data+p2->data; carry=0;}
if((p1->data+p2->data+carry)==0) break;
p1=p1->next;
p2=p2->next;
p->next=q;
q->prev=p;
p=q;
}
p->next=tmp.tail;
tail->prev=p;
tail->next=NULL;
head->prev=NULL;
return tmp;
}
int main()
{
linklist number1,number2,number3;
number1.setup();
number2.setup();
number3=number1+number2;
number3.show();
return 0;
}