类和链表

lovelylan9510 2008-12-06 11:37:06
在调试的时候,当我选择1.3.8.10的操作时,它总能输出正确的答案,但紧接着程序就被终止了.那个错误提示没看懂,谁能教我一下吗?
还有就是,怎么让它循环操作啊?比如说当用户输入11的时候,程序终止?我希望里面的内容是连续的,不是每进行一次,数据就初始化一次
万分感谢!
(我还没学到模板...)
#include <iostream>
using namespace std;
struct Node
{
int content;
Node *next;
};
class Set
{ Node *node;
Node *head;
public:
Set();
Set(const Set& s);
~Set();
bool is_empty() const
{
return (head==NULL);
}
bool is_element(int e) const
{
Node *q=head;
for(;q!=NULL;q=q->next)
if(q->content==e)
return true;
return false;
}
Set union2(const Set& s) const
{
Set bing(*this);
Node *p=s.head;
for(;p!=NULL;p=p->next)
if(!is_element(p->content))
bing.insert(p->content);
bing.display();
return bing;
}
Set difference(const Set& s) const
{
Set cha(*this);
Node *p=s.head;
for(;p!=NULL;p=p->next)
if(is_element(p->content))
cha.remove(p->content);
cha.display();
return cha;
}
};
void at(Set A,int element)
{
if(A.is_element(element))
cout<<"有该元素"<<endl;
else
cout<<"没有该元素"<<endl;
}
void kongji(Set A)
{
if(A.is_empty())
cout<<"是空集"<<endl;
else
cout<<"不是空集"<<endl;
}
int main()
{
Set A,B;
cout<<"请输入集合A中的元素,以-1结束:"<<endl;
creat(A);
cout<<"请输入集合B中的元素,以-1结束:"<<endl;
creat(B);
cout<<"请选择要做的操作:"<<endl;
cout<<"1.判断是否为空集"<<endl;
cout<<"3.判断某元素是否在集合中"<<endl;
cout<<"8.计算集合的并集"<<endl;
cout<<"10.计算集合的差"<<endl;
int pd;
cin>>pd;
switch(pd)
{ case 1: cout<<"A";
kongji(A);
cout<<"B";
kongji(B);
break;
case 3: cout<<"请输入该元素:";
int element;
cin>>element;
cout<<"集合A中";
at(A,element);
cout<<"集合B中";
at(B,element);
break;
case 8:A.union2(B);break;
case 10:cout<<"A-B为{";
A.difference(B);
cout<<"}"<<endl;
cout<<"B-A为{";
B.difference(A);
cout<<"}"<<endl;break;
default:cout<<"Input Error!"<<endl;
}
return 0;
}

...全文
104 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
太乙 2008-12-07
  • 打赏
  • 举报
回复
upup~~~~
lovelylan9510 2008-12-07
  • 打赏
  • 举报
回复
我重新贴了....本来因为怕帖子太长,把你们都吓跑了....
bingshanzhiling 2008-12-07
  • 打赏
  • 举报
回复
ls几个说的很明白,不贴全怎么看啊,说不定问题就出现在你没贴的上面。。。
toadzw 2008-12-06
  • 打赏
  • 举报
回复
insert
nullah 2008-12-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 Chiyer 的回复:]
把代码贴全阿

你的 insert 函数呢?
[/Quote]
基本每个帖子都能看到你 呵呵
星羽 2008-12-06
  • 打赏
  • 举报
回复
把代码贴全阿

你的 insert 函数呢?
星羽 2008-12-06
  • 打赏
  • 举报
回复
把代码贴全阿

你的 insert 函数呢?

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧