my code has many bugs, I don't know how to do,please help,and it's very urgent
#include<iostream>
using namespace std;
struct node
{int data;node *next,*previous;};
void creat(node *&head)
{node *s,*p;
char num[100];
cin>>num;
int i=0;
s=new node;
s->data=num[i]-48;
while(num[i]!='\0')
{ if(head==NULL) head=s;
else {p->next=s;s->previous=p;}
i++;
p=s;
s=new node;
s->data=num[i]-48;
}
p->next=NULL;
head->previous=NULL;
delete s;
return;
}
void plus(node *head1,node *head2)
{int number[100];
int q=1,p=1,m=0,i;
while(head1->next!=NULL) {head1=head1->next;p++;}
while(head2->next!=NULL) {head2=head2->next;q++;}
if(p==q)
{for(i=0;p>0;i++,p--,q--)
{number[i]= head1->data+head2->data+m;
if(number[i]>9) m=1,number[i]-=10;
else m=0;
head1=head1->previous;
head2=head2->previous;
}
if(m==1) number[i]=1,i++;
}
else if(p>q)
{for(i=0;q>0;i++,q--,p--)
{number[i]= head1->data+head2->data+m;
if(number[i]>9) m=1,number[i]-=10;
else m=0;
head1=head1->previous;
head2=head2->previous;}
while(p>0)
{number[i]=head1->data+m;
if(number[i]>9) m=1,number[i]-=10;
else m=0;
i++;
p--;
head1=head1->previous;}
if(m==1) number[i]=1;i++;
}
else
{for(i=0;p>0;i++,p--,q--)
{number[i]= head1->data+head2->data+m;
if(number[i]>9) m=1,number[i]-=10;
else m=0;
head1=head1->previous;
head2=head2->previous;}
while(q>0)
{number[i]=head2->data+m;
if(number[i]>9) m=1,number[i]-=10;
else m=0;
i++;
q--;
head2=head2->previous;}
if(m==1) number[i]=1,i++;
}
for(i=i-1;i>=0;i--)
{cout<<number[i];}
cout<<endl;
}
void minus(node *head1,node *head2)
{int number[100];
int q=1,p=1,m=0,i,a,b,z;
node *head;
while(head1->next!=NULL) {head1=head1->next;p++;}
while(head2->next!=NULL) {head2=head2->next;q++;}
if(p>q)
{for(i=0;q>0;q--,p--,i++)
{if((head1->data-m)>=head2->data) number[i]=head1->data-head2->data-m;
else number[i]=head1->data+10-head2->data-m,m=1;
head1=head1->previous;
head2=head2->previous;
}
for( ;p>0;p--,i++)
{if(number[i]=head1->data-m<0) number[i]=head1->data-m,m=0;
else number[i]=head1->data+10-m;m=1;
head1=head1->previous;}
i=i-1;
for( ;i>=0;i--)
{cout<<number[i];}
cout<<endl;
}
else if(p<q)>
{for(i=0;p>0;q--,p--,i++)
{if((head2->data-m)>=head1->data) number[i]=head2->data-head1->data-m;
else {number[i]=head2->data+10-head1->data-m;m=1;}
head1=head1->previous;
head2=head2->previous;}
for( ;q>0;q--,i++)
{if(number[i]=head2->data-m<0) number[i]=head2->data-m,m=0;
else number[i]=head2->data+10-m;m=1;
head2=head2->previous;}
i=i-1;
cout<<'-';
for( ;i>=0;i--)
{cout<<number[i];}
cout<<endl;
}
else
{while(head1->previous!=NULL){head1=head1->previous;}
while(head1->previous!=NULL) {head2=head2->previous;}
for( ;head1->next!=NULL;head1=head1->next,head2=head2->next)
{a=head1->data;
b=head2->data;
if(b>a) {head=head1;head1=head2;head2=head;z=0;break;}
if(a>b) {z=1;break;}
z=1;
}
while(head1->next!=NULL) {head1=head1->next;}
while(head2->next!=NULL) {head2=head2->next;}
for(i=0;q>0;q--,i++)
{if((head1->data-m)>=head2->data) number[i]=head1->data-head2->data-m;
else {number[i]=head1->data-head2->data-m+10;m=1;}
head1=head1->previous;
head2=head2->previous;
}
i=i-1;
while(number[i]==0) {i--;}
if(i==-1) cout<<'0';
else
{if(z==0) cout<<'-';
for( ;i>=0;i--)
{cout<<number[i];}}
cout<<endl;
}
}
int main()
{node *head1=NULL,*head2=NULL;
creat(head1);
creat(head2);
minus(head1,head2);
}