帮我看一下,十分感谢,我C++学的不好。
#include<iostream>
using namespace std;
struct Node
{
char data;
Node *next;
};
Node *Create(Node *head)
{
char ch; Node*pNew,*pCur;
pNew=new Node;
cin>>ch;pNew->data=ch;
while(ch!='#')
{
if(NULL==head)
head=pNew;
else
pCur->next=pNew;
pCur=pNew;
pNew=new Node;
cin>>ch;
}
pCur->next=NULL;
return head;
}
void Interest(Node *head1,Node*head2)
{
Node *pre,*p,*q;
pre=head1;p=head1->next;q=head2->next;
while(p&&q)
{
if((p->data)<(q->data))
{
pre->next=p->next; p=pre->next;
}
else if((p->data)>(q->data))q=q->next;
else{
p=p->next;q=q->next;
}
}
}
void OutList(Node *head)
{
Node *pre=head->next;
while(pre!=NULL)
{
cout<<pre->data;
pre=pre->next;
}
}
int main()
{
char cmd;
do{
cout<<"输入两个**的元素,输完一个**的元素,按#结束\n";
Node *head1=Create(head1);
Node *head2=Create(head2);
Interest(head1,head2);
cout<<"两个**差集为\n";
OutList(head1);
cout<<"按y/Y继续,否则结束\n";
cin>>cmd;
}while(cmd=='y'||cmd=='Y');
return 0;
}
#include<iostream>
using namespace std;
struct Node
{
char data;
Node *next;
};
Node *Create(Node *head)
{
char ch; Node*pNew,*pCur;
pNew=new Node;
cin>>ch;pNew->data=ch;
while(ch!='#')
{
if(NULL==head)
head=pNew;
else
pCur->next=pNew;
pCur=pNew;
pNew=new Node;
cin>>ch;
}
pCur->next=NULL;
return head;
}
void Interest(Node *head1,Node*head2)
{
Node *pre,*p,*q;
pre=head1;p=head1->next;q=head2->next;
while(p&&q)
{
if((p->data)<(q->data))
{
pre->next=p->next; p=pre->next;
}
else if((p->data)>(q->data))q=q->next;
else{
p=p->next;q=q->next;
}
}
}
void OutList(Node *head)
{
Node *pre=head->next;
while(pre!=NULL)
{
cout<<pre->data;
pre=pre->next;
}
}
int main()
{
char cmd;
do{
cout<<"输入两个**的元素,输完一个**的元素,按#结束\n";
Node *head1=Create(head1);
Node *head2=Create(head2);
Interest(head1,head2);
cout<<"两个**差集为\n";
OutList(head1);
cout<<"按y/Y继续,否则结束\n";
cin>>cmd;
}while(cmd=='y'||cmd=='Y');
return 0;
}