Home > Back-end >  Error: 2440 how should solve?
Error: 2440 how should solve?

Time:09-20

 
#include
using namespace std;
//poly real data type
Typedef struct DataType {
Int coef.
Int expn;
Struct DateType * next;
} the data;

//initialization expression
Data * Initlist (void)
{
Data * head;
If ((head=(data *) malloc (sizeof (data)))==NULL)
exit(-1);
The head - & gt; Next=NULL;

return head;
}

//release list
/* void deleteList (data * head)
{
Temp1 data * and * temp2;
Temp1=head - & gt; Next;
While (temp1!=NULL)
{
Temp2=temp1 - & gt; Next;
The delete temp1;
Temp1=temp2;
}
The head - & gt; Next=NULL;
Delete the head;
} */

//destruction list
/* void DesList (data * head)
{
FreeList (pHead);
Free (pHead);
} */

//input expression
Void Inputlist (data * head)
{
Int coef expn;
Tail data * and * xin;
Tail=head;

While (1)
{
Cout<& lt;" Please input (coefficient of index), index, increasing the input, the coefficient of 0 means that the end of input: ";
Cin> Coef> Expn;
If (coef!=0)
{
If ((xin=(data *) malloc (sizeof (data)))==NULL)
{
exit(-1);
}
Xin - & gt; Coef=coef;
Xin - & gt; Expn=expn;
Tail - & gt; Next=xin;
Tail=xin;
}
The else {
break;
}
}

Tail - & gt; Next=NULL;
}

//output expression
Void Outputlist (data * head)
{
Data * temp;
Temp=head - & gt; Next;

If (temp==NULL) {
Coutreturn;
}
CoutTemp=temp - & gt; Next;

while(temp !=NULL) {
CoutTemp=temp - & gt; Next;
}
Cout}

//expressions add
Data * Addlist (data * head1, data * head2)
{
Int temp.
Xin head3 data * and * and * tail;//the result list relevant variables
Temp1 data * and * temp2;//operation list relevant variables

Temp1=head1 - & gt; Next;
Temp2=head2 - & gt; Next;
Head3=Initlist ();
Tail=head3;

//put two scan arithmetic polynomial in the results list
While (temp1!=NULL & amp; & Temp2!=NULL) {
//if equal index
If (temp1 - & gt; Expn==temp2 - & gt; Expn) {

If ((temp=temp1 - & gt; Coef + temp2 - & gt; Coef)==0)
{
Temp1=temp1 - & gt; Next;
Temp2=temp2 - & gt; Next;
The continue;
}
If ((xin=(data *) malloc (sizeof (data)))==NULL)
exit(-1);
Xin - & gt; Coef=temp;
Xin - & gt; Expn=temp1 - & gt; Expn;
Tail - & gt; Next=xin;
Xin - & gt; Next=NULL;
Tail=xin;
Temp1=temp1 - & gt; Next;
Temp2=temp2 - & gt; Next;

}//if the expression 1 index less than 2
Else if (temp1 - & gt; Expn & lt; Temp2 - & gt; Expn)
{
If ((xin=(data *) malloc (sizeof (data)))==NULL)
exit(-1);
* xin=* temp1;
Xin - & gt; Next=NULL;
Tail - & gt; Next=xin;
Tail=xin;
Temp1=temp1 - & gt; Next;
}//if the expression 1 index greater than 2
The else {
If ((xin=(data *) malloc (sizeof (data)))==NULL)
exit(-1);
* xin=* temp2;
Xin - & gt; Next=NULL;
Tail - & gt; Next=xin;
Tail=xin;
Temp2=temp2 - & gt; Next;
}
}
//put the rest of the scan option in the result list
While (temp1!=NULL) {
If ((xin=(data *) malloc (sizeof (data)))==NULL)
exit(-1);
* xin=* temp1;
Xin - & gt; Next=NULL;
Tail - & gt; Next=xin;
Tail=xin;
Temp1=temp1 - & gt; Next;
}
While (temp2!=NULL) {
If ((xin=(data *) malloc (sizeof (data)))==NULL)
exit(-1);
* xin=* temp2;
Xin - & gt; Next=NULL;
Tail - & gt; Next=xin;
Tail=xin;
Temp2=temp2 - & gt; Next;
}

Return head3;
}

//two polynomial subtraction
Data * Sublist (data * head1, data * head2)
{
Head3 data * and * temp;
Temp=head2 - & gt; Next;

//be reduced expression of each coefficient multiplied by 1
while(temp !=NULL) {
Temp - & gt; Temp coef=1 * - & gt; Coef.
Temp=temp - & gt; Next;
}

Head3=Addlist (head1, head2);

//will be reduced expression value recovery
Temp=head2 - & gt; Next;
while(temp !=NULL) {
Temp - & gt; Temp coef=1 * - & gt; Coef.
Temp=temp - & gt; Next;
}
Return head3;
}

Int main ()
{
Head2 head1 data * and * * result;
Head1=Initlist ();
Inputlist (head1);
Head2=Initlist ();
Inputlist (head2);
Cout<& lt;" The expression 1: ";
Outputlist (head1);
Cout<& lt;" Expression 2: ";
Outputlist (head2);
Result=Addlist (head1, head2);
Cout<& lt;" Expression 1 + 2=";
Outputlist (result);
DeleteList (result);
Result=Sublist (head1, head2);
Cout<& lt;" 1-2="expression expression;
Outputlist (result);
DeleteList (result);
DeleteList (head1);
DeleteList (head2);
return 0;
}

  • Related