c++链表输入一元方程,救命啊!!!!!!!!!!!!!

来源:百度知道 编辑:UC知道 时间:2024/05/02 18:10:29
#include<iostream.h>
struct duo
{long ne;
long nf;
duo*next;};
duo *creat()
{duo*h,*q,*p;duo*temp;
temp=p;
h=NULL;
p=new duo;
q=p;
cout<<endl;
cin>>p->ne>>p->nf;
while(((p->ne!=0)&&(p->nf!=0))||((p->ne!=0)&&(p->nf==0))||((p->ne==0)&&(p->nf!=0)))
{if(h==NULL)h=p;
else
if(q->ne<p->ne)
{temp->ne=q->ne;
q->ne=p->ne;
p->ne=temp->ne;
temp->nf=q->nf;
q->nf=p->nf;
p->nf=temp->nf;
}
q->next=p;
q=p;
p=new duo;
cin>>p->ne>>p->nf;
}
q->next=NULL;
return h;
}
void print(duo*h)
{duo*p;
p=h;
if(h==NULL)cout<<"The list is NULL!\n";
else
cout<<p->nf<<"X"<<p->ne;
p=p->next;
while(

#include<iostream.h>
struct duo
{
long ne;
long nf;
duo *next;
};
duo *creat()
{
duo *h,*q,*p,*s,*t;
duo *temp,*head;
h=NULL;
p=new duo;
cout<<"输入:";
cin>>p->ne>>p->nf;
while(((p->ne!=0)&&(p->nf!=0))||((p->ne!=0)&&(p->nf==0))||((p->ne==0)&&(p->nf!=0)))
{
if(h==NULL)
{
h=p;
head=p;
q=p;
q->next=NULL;
}
else //不为空,接在后面
{
if(q->ne>p->ne)
{
q->next=p;
q=p;
q->next=NULL;
}
else
{
s=head;
if(p->ne>s->ne)
{
head=p;
head->next=s;
h=head;
}
if(p->ne==s->ne)
{
s->nf+=p->nf;
}
if(p->ne<s->ne)
{
while(true)