Home > Back-end >  Vs2019 memory read/write error, please advise
Vs2019 memory read/write error, please advise

Time:12-05

Polynomial of power of the following procedures: drop list form combined function, when the part to the red words below shows that read data error, debug data found at this time for p1=??????? When should trigger the conditions in the outer while loop and jump out, but always jump out, turn to the great god why
 
Poly real * add (poly real * p1, p2) poly real *
{
Poly real * result=nullptr;
Poly real * result_head=nullptr;
While (p2!=nullptr& & P1!=nullptr)
{
If (p1 - & gt; Times & lt; The p2 - & gt; Times)
{
If (result!=nullptr)
Result=result - & gt; Next=p2;
The else result=p2;
The p2=p2 - & gt; next;
If (result_head==nullptr) result_head=the result;
}
If (p1 - & gt; Times & gt; The p2 - & gt; Times)
{
If (result!=nullptr)
Result=result - & gt; Next=p;
The else result=p1;
P1=p1 - & gt; next;
If (result_head==nullptr) result_head=the result;
}
If (p1 - & gt; Times==p2 - & gt; Times)
{
Poly real * temp=(poly real *) malloc (sizeof (poly real));
Temp - & gt; Coef=p1 - & gt; Coef + p2 - & gt; Coef.
Temp - & gt; Times=p1 - & gt; Times;
If (temp - & gt; Coef!=0)
{
P1=p1 - & gt; next;
The p2=p2 - & gt; next;
If (result!=nullptr)
Result=result - & gt; Next=temp;
The else result=temp;
If (result_head==nullptr) result_head=the result;
}
The else//if the coefficient and 0
{
P1=p1 - & gt; next;
The p2=p2 - & gt; next;
}
}
}
If (p1==nullptr& & The p2! Result==nullptr) result - & gt; Next=p2;
If (p1!=nullptr & amp; & P2==nullptr) result=result - & gt; Next=p;
If (p1==nullptr & amp; & The p2==nullptr);
Return result_head;
}


Test data:
4
3 4 5 6 1-2 0
3
5 20-7 4 3 1
(original intention is to realize the power polynomial list form together)

CodePudding user response:

No value given the p2

CodePudding user response:

Hello, this does show is the p2 no value, but at this time should be morally has jumped out of the outer while loop, why will he in there?
  • Related