codeblocks里面在执行到insert函数里输入数字的时候按回车键就会有对话框提示停止工作
#include<iostream>#include<cstdio>usingnamespacestd;structNode{doubledata;Node*next;}...
#include<iostream>
#include<cstdio>
using namespace std;
struct Node
{double data;
Node*next;
};
class LB
{ Node*first;
public:
LB()
{
first=new Node;
first->next=NULL;
}
~LB()
{
while(first!=NULL)
{
Node *q;q=first;
first=first->next;delete q;
}
}
void insert();
void paixu();
void inverse();
};
void LB::paixu()
{Node*p,*q;
p=first->next;
while(p)
{
q=p->next;
while(q!=NULL)
if(p->data>q->data)
{Node *m;
m->data=p->data;
p->data=q->data;
q->data=m->data;q=q->next;cout<<p->data;
}
p=p->next;
}
}
void LB::insert()
{int i;Node *p=first;double a;
cin>>a;
while(a!=0)
{
Node *q;
q->data=a;
p->next=q;
p=q;
cin>>a;
}
p->next=NULL;;
p=first->next;cout<<"链表元素:"
while(p)
cout<<p->data;
}
void LB::inverse()
{Node *q=first,*p=NULL;Node *r;
while(q)
{r=p;
p=q;
q=q->next;
p->next=r;
}
while(p)
{cout<<p->data;
p=p->next;}
}
int main()
{LB A;
cout<<"请输入数据(以空格隔开,以0结束,最多1000组数据):";
A.insert();
A.paixu();
A.inverse();
} 展开
#include<cstdio>
using namespace std;
struct Node
{double data;
Node*next;
};
class LB
{ Node*first;
public:
LB()
{
first=new Node;
first->next=NULL;
}
~LB()
{
while(first!=NULL)
{
Node *q;q=first;
first=first->next;delete q;
}
}
void insert();
void paixu();
void inverse();
};
void LB::paixu()
{Node*p,*q;
p=first->next;
while(p)
{
q=p->next;
while(q!=NULL)
if(p->data>q->data)
{Node *m;
m->data=p->data;
p->data=q->data;
q->data=m->data;q=q->next;cout<<p->data;
}
p=p->next;
}
}
void LB::insert()
{int i;Node *p=first;double a;
cin>>a;
while(a!=0)
{
Node *q;
q->data=a;
p->next=q;
p=q;
cin>>a;
}
p->next=NULL;;
p=first->next;cout<<"链表元素:"
while(p)
cout<<p->data;
}
void LB::inverse()
{Node *q=first,*p=NULL;Node *r;
while(q)
{r=p;
p=q;
q=q->next;
p->next=r;
}
while(p)
{cout<<p->data;
p=p->next;}
}
int main()
{LB A;
cout<<"请输入数据(以空格隔开,以0结束,最多1000组数据):";
A.insert();
A.paixu();
A.inverse();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询