调试的时候总是提示新的链表没有被初始化,求大神解决
#include<iostream>
#include<iomanip>
using namespace std;
struct Lnode
{
int data;
Lnode *prior;
Lnode *next;
};
class CDoubleLinkList
{
//private:
// Lnode *head;
public:
Lnode *head;
void creatList()
{
Lnode *s,*r;
head =new Lnode;
head->data=0;
head->prior=NULL;
head->next=NULL;
r=head;
cout<<"Please input the data of your doubleLinkList and when the data is zero the pro end"<<endl;
int n;
cin>>n;
while(n!=0)
{
s=new Lnode;
s->data=n;
r->next=s;
s->prior=r;
r=s;
cin>>n;
}
r->next=NULL;
}
void dispList()
{
Lnode *p=head->next;
while(p)
{
cout<<setw(3)<<p->data;
p=p->next;
}
cout<<endl;
}
};
CDoubleLinkList initList(CDoubleLinkList a)
{
a.head->data=0;
a.head->prior=NULL;
a.head->next=NULL;
return a;
}
CDoubleLinkList sendList(CDoubleLinkList a,CDoubleLinkList b)//调试提示c没有被初始化
{
Lnode *p=a.head->next;
Lnode *q=b.head->next;
CDoubleLinkList c;
initList(c);
Lnode *t=c.head->next;
int t1=0,t2=0;
while(p&&q)
{
t1=p->data;
t2=q->data;
if (t1==t2)
{
t->data=t1;
t=t->next;
}
p=p->next;
q=q->next;
}
return c;
}
int main()
{
CDoubleLinkList h,j;
h.creatList();
h.dispList();
j.creatList();
j.dispList();
sendList(h,j);
return 0;
}
å ·ä½åºè¯¥æä¹æ¹å¢ï¼
追çsendList è¦å®ç°ä»ä¹åè½
追é®æ é¢ä¸è¯´çåæ两个é¾è¡¨ä¸ç¸åçå¼èµç»ä¸ä¸ªæ°çé¾è¡¨