我需要编写一个通过修改当前多项式来求导的方法。我可以写一个与返回类型一起工作的。这是代码:
public PolynomialSortedList differentiate() {
PolynomialSortedList res = new PolynomialSortedList();
for(PolyNode tmp = poly; tmp != null; tmp = tmp.next)
{
if(tmp.exp != 0)
res.addTerm(tmp.coef * tmp.exp, tmp.exp - 1 );
}
return res;
}
如何使用代码的上半部分将其变为 void:
public class PolynomialSortedList implements Polynomial {
private PolyNode poly;
private double TOLERANCE = 0.00000001;
public PolynomialSortedList() {
poly = null;
}
private static class PolyNode {
int coef;
int exp;
PolyNode next;
PolyNode(int coef, int exp,PolyNode next) {
this.coef = coef;
this.exp = exp;
this.next = next;
}
}
}