Skip to content

Commit

Permalink
修复了在某些多项式除法中会导致某个多项式变量的长度为0,从而导致内存泄露的问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoXueTu555 committed Aug 13, 2023
1 parent ec06eba commit b488d71
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 10 deletions.
19 changes: 17 additions & 2 deletions SeekAnAnswer/SeekAnAnswer/kernel/polynomial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@ Polynomial Polynomial::operator/(Polynomial val)
return result;
}

//将被除数和除数最高的单项式的次数的单项式移动到首位
/*将被除数和除数最高的单项式的次数的单项式移动到首位
且首位保证是字母集合元素最少的单项式*/
this->Move(); val.Move();

//被除数与除数相等
Expand All @@ -608,6 +609,16 @@ Polynomial Polynomial::operator/(Polynomial val)
//清空商式的所有项
result.list.clear();

//如果不能进行因式分解算法则进行长除法
if (!IsParentPolynomial(remainder, val) ||
remainder.GetDegree().GetDegree() < val.GetDegree().GetDegree() ||
(remainder.IsMonomial() && remainder.list.at(0) == Monomial("(0/1)")) ||
(result.list.size() >= this->list.size())
)
{
goto division_method;
}

/*如果“余式不是除式的子多项式”、“余式的次数小于除式的次数”、
“余式等于0”、“商多项式的项数大于等于被除式的项数”
其一满足,则因式分解结束,否则可进行因式分解*/
Expand Down Expand Up @@ -673,7 +684,11 @@ Polynomial Polynomial::operator/(Polynomial val)
}
}

result.DeleteZero(); //bug
//防止某些运算提前结束导致长度为0
if (result.list.size() == 0)
result.Push(Monomial());

result.DeleteZero();

result.Unite_like_terms();

Expand Down
16 changes: 8 additions & 8 deletions examples/ImGui_Test_Calculator/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ Size=142,71
Collapsed=0

[Window][Test_Calculator]
Pos=28,17
Pos=47,41
Size=598,214
Collapsed=0

[Window][SeekAnAnswer test]
Pos=205,81
Pos=171,129
Size=788,361
Collapsed=0

Expand All @@ -54,8 +54,8 @@ Size=474,251
Collapsed=0

[Window][Test Polynomial MUL]
Pos=545,263
Size=577,355
Pos=375,271
Size=689,361
Collapsed=0

[Window][Test Polynomial division]
Expand All @@ -74,8 +74,8 @@ Size=540,210
Collapsed=0

[Window][Test solution equation ]
Pos=241,117
Size=730,399
Pos=508,360
Size=544,260
Collapsed=0

[Window][Test Monomial divition]
Expand All @@ -84,8 +84,8 @@ Size=339,201
Collapsed=0

[Window][Arithmetic test]
Pos=434,257
Size=567,322
Pos=83,429
Size=636,270
Collapsed=0

[Window][Monomial Substitute Test]
Expand Down
Binary file added img-storage/Equation-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img-storage/ImGui-test1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img-storage/ImGui-test2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img-storage/ImGui-test3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img-storage/ImGui-test4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img-storage/ImGui-test5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img-storage/ImGui-test6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img-storage/Polynomial-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b488d71

Please sign in to comment.